Skip to content

Commit

Permalink
[PL] Revert ranges to for-range loop
Browse files Browse the repository at this point in the history
Unfortunately with gcc-13.2.1 with optimizations there is a warning, which I was not able to correct.

    ...
    inlined from ‘std::vector<std::tuple<long int, std::reference_wrapper<ProcessLib::LocalAssemblerInterface> > > {anonymous}::collectActiveLocalAssemblers(const BaseLib::PolymorphicRandomAccessContainerView<ProcessLib::LocalAssemblerInterface>&, const std::vector<long unsigned int>&)’ at /var/lib/gitlab-runner/builds/F1XUyv4cx/1/ogs/ogs/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp:132:62:
/usr/include/c++/13.2.1/bits/stl_iterator_base_funcs.h:175:9: warning: iteration 576460752303423487 invokes undefined behavior [-Waggressive-loop-optimizations]
  175 |         while (__n--)
      |         ^~~~~
/usr/include/c++/13.2.1/bits/stl_iterator_base_funcs.h:175:9: note: within this loop

Other compilers gcc-14, clang-17 and 18, msvc had no problems with the
former code.
  • Loading branch information
endJunction committed Aug 14, 2024
1 parent 403ae53 commit 53321f2
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

#include <cstdlib>
#include <fstream>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/transform.hpp>
#include <range/v3/view/zip.hpp>
#include <vector>

#include "BaseLib/StringTools.h"
Expand Down Expand Up @@ -115,15 +112,18 @@ collectActiveLocalAssemblers(
ProcessLib::LocalAssemblerInterface> const& local_assemblers,
std::vector<std::size_t> const& active_elements)
{
auto id_and_local_asm = [&local_assemblers](std::size_t const id)
-> std::tuple<std::ptrdiff_t, std::reference_wrapper<
ProcessLib::LocalAssemblerInterface>>
{ return {id, local_assemblers[id]}; };

auto create_ids_asm_pairs = [&](auto const& element_ids)
{
return element_ids | ranges::views::transform(id_and_local_asm) |
ranges::to<std::vector>();
std::vector<std::tuple<
std::ptrdiff_t,
std::reference_wrapper<ProcessLib::LocalAssemblerInterface>>>
result;
result.reserve(static_cast<std::size_t>(element_ids.size()));
for (auto const id : element_ids)
{
result.push_back({id, local_assemblers[id]});
}
return result;
};

if (active_elements.empty())
Expand Down

0 comments on commit 53321f2

Please sign in to comment.