llnl / llnl/RAJAPerf

does SORTPAIRS need to use reserve+emplace_back?

Open
#262 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement question
Dominant language
Jupyter Notebook
Stars
135
Forks
55
Avg merge
4d 16h
Merged PRs (30d)
5

Description

I am working on the C++17 parallel version of SORTPAIRS, and I cannot use `emplace_back` there. I find that I can switch from `reserve` to `resize` and use simple assignment instead of `emplace_back`, but I don't know if this consistent with the intent.

Unfortunately, I don't see any non-RAJA parallel references to guide me here. The OMP and CUDA parallel versions just call `the RAJA::sort_pairs` method.

If it is allowed to use `resize+(assign)` instead, I'll make that change in the sequential implementation, independent of what I'm doing with C++ parallelism.

Thanks!

# old
```
vector_of_pairs.reserve(iend-ibegin);

std::for_each( //std::execution::par, // parallelism leads to incorrectness
begin,end,
[=,&vector_of_pairs](Index_type iemp) noexcept {
vector_of_pairs.emplace_back(x[iend*irep + iemp], i[iend*irep + iemp]);
});
```
# new
```
vector_of_pairs.resize(iend-ibegin);

std::for_each( std::execution::par,
begin,end,
[=,&vector_of_pairs](Index_type iemp) noexcept {
vector_of_pairs[iemp] = std::make_pair(x[iend*irep + iemp], i[iend*irep + iemp]);
});
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the sequential SORTPAIRS implementation and the RAJA::sort_pairs entry point. Compare the reserve+emplace_back and resize+assignment approaches with the C++17 parallel constraints described here, then determine whether the sequential implementation should adopt the alternative. Done means the intended approach is confirmed and the relevant implementation is consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.