Skip to content

added Scatter and Gather implementations in PLUMED Communicator#1381

Open
aalhossary wants to merge 2 commits intoplumed:masterfrom
aalhossary:add-scatter-and-gather-to-communicator
Open

added Scatter and Gather implementations in PLUMED Communicator#1381
aalhossary wants to merge 2 commits intoplumed:masterfrom
aalhossary:add-scatter-and-gather-to-communicator

Conversation

@aalhossary
Copy link

@aalhossary aalhossary commented Mar 18, 2026

Description

The MPI Communicator does not have Scatter and Gather implementations (It has AllScatter but not Scatter).
Here is an implementation of them for future use.
I need them in my development.

Type of contribution
  • changes to code or doc authored by PLUMED developers, or additions of code in the core or within the default modules
  • changes to a module not authored by you
  • new module contribution or edit of a module authored by you
Copyright
  • I agree to transfer the copyright of the code I have written to the PLUMED developers or to the author of the code I am modifying.
  • the module I added or modified contains a COPYRIGHT file with the correct license information. Code should be released under an open source license. I also used the command cd src && ./header.sh mymodulename in order to make sure the headers of the module are correct.
Tests
  • I added a new regtest or modified an existing regtest to validate my changes.
  • I verified that all regtests are passed successfully on GitHub Actions.

@GiovanniBussi
Copy link
Member

thanks for your contribution! Can you also add regtets? I guess the correct places are:

  • regtest/basic/rt-make-2, to test the behavior when compiled with MPI
  • regtest/basic/rt-make-7, to test the behavior when compiled without MPI

It should be as simple as:

  • edit the main.cpp file
  • type "make"

Note that test number 7 uses asserts, whereas test number 2 writes on a file. The second approach is a bit better, because in case of multiple functions it allows to see that only one failed. The first approach will just crash. Please follow the convention in the respective file.

Thanks again!

- Added Scatter/Gather tests to rt-make-2 (MPI version)
- Added Scatter/Gather tests to rt-make-7 (non-MPI version)
- Updated reference output files
reset(comm,a);
std::vector<int> gather_send(4);
std::vector<int> gather_recv(4*comm.Get_size(),0);
for(unsigned i=0;i<gather_send.size();i++) gather_send[i]=(i+1)*(comm.Get_rank()+1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make more clear who is sending the data and break some line, like this:

Suggested change
for(unsigned i=0;i<gather_send.size();i++) gather_send[i]=(i+1)*(comm.Get_rank()+1);
for(unsigned i=0;i<gather_send.size();i++) {
gather_send[i]=1+i+(comm.Get_rank()+1)*100;
}

So we expect 101 102 103 104 201 202 203 204 301 302 303 304, and if something is wrong is faster to understand where

If you want you can apply a similar idea also to the scatter test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants