Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C bindings in MPI example #81

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/extended/parallel/MPI/History
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ See `CONTRIBUTING.rst` for details of **required** info/format for each entry,
which **must** added in reverse chronological order (newest at the top). It must **not**
be used as a substitute for writing good git commit messages!

## 2025-02-24 Filippo Falezza (MPI-V11-03-00)
- Rewritten G4MPI to use C bindings (MPI 3+)
- Fixes [GitHub PR #81](https://github.com/Geant4/geant4/pull/81/)

## 2023-03-11 Ben Morgan (MPI-V11-02-00)
- Move CTests definitions to tests/ctests_examples

Expand Down
6 changes: 3 additions & 3 deletions examples/extended/parallel/MPI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ http://www.open-mpi.org/
MPI support:
------------
G4mpi has been tested with the following MPI flavors:
* OpenMPI 1.8.1
* MPICH 3.2
* Intel MPI 5.0.1
* OpenMPI 5.0.2 and 4.1.4
* ~~MPICH 3.2~~
* ~~Intel MPI 5.0.1~~

### CMake

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ void RunMerger::Pack()
{
// Very imporant, here fMyRun is const!
// Register a user-data in the user Run class with MPI merger
InputUserData(const_cast<int*>(&(fMyRun->fDummyCounter)), MPI::INT, 1);
InputUserData(const_cast<int*>(&(fMyRun->fDummyCounter)), MPI_INT, 1);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4Run* RunMerger::UnPack()
{
// Create a dummy user-Run, used to contain data received via MPI
Run* aDummyRun = new Run;
OutputUserData(&(aDummyRun->fDummyCounter), MPI::INT, 1);
OutputUserData(&(aDummyRun->fDummyCounter), MPI_INT, 1);
return aDummyRun;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ void RunMerger::Pack()
{
// Very imporant, here fMyRun is const!
// Register a user-data in the user Run class with MPI merger
InputUserData(const_cast<int*>(&(fMyRun->fDummyCounter)), MPI::INT, 1);
InputUserData(const_cast<int*>(&(fMyRun->fDummyCounter)), MPI_INT, 1);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4Run* RunMerger::UnPack()
{
// Create a dummy user-Run, used to contain data received via MPI
Run* aDummyRun = new Run;
OutputUserData(&(aDummyRun->fDummyCounter), MPI::INT, 1);
OutputUserData(&(aDummyRun->fDummyCounter), MPI_INT, 1);
return aDummyRun;
}
10 changes: 8 additions & 2 deletions examples/extended/parallel/MPI/source/include/G4MPImanager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <fstream>
#include <pthread.h>
#include <vector>

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
Expand Down Expand Up @@ -123,11 +124,14 @@ class G4MPImanager
// misc
void ShowHelp() const;

const MPI::Intracomm* GetComm() const { return &COMM_G4COMMAND_; }
const MPI_Comm* GetComm() const { return &COMM_G4COMMAND_; }
const MPI_Comm* GetProcessingComm() const { return &processing_comm_; }
const MPI_Comm* GetCollectingComm() const { return &collecting_comm_; }
const MPI_Comm* GetAllComm() const { return &all_comm_; }

std::vector<G4String> ReturnArguments() { return _options; }


private:
DISALLOW_COPY_AND_ASSIGN(G4MPImanager);

Expand Down Expand Up @@ -157,7 +161,7 @@ class G4MPImanager
G4int world_size_; // world comm size

// MPI communicator (when no extra ranks)
MPI::Intracomm COMM_G4COMMAND_;
MPI_Comm COMM_G4COMMAND_;
// MPI communicator (processing ranks - if ntuple merging)
MPI_Comm processing_comm_;
// MPI communicator (collecting ranks - if ntuple merging)
Expand Down Expand Up @@ -188,6 +192,8 @@ class G4MPImanager
// parallel parameters
G4double master_weight_;
G4int nof_extra_workers_;

std::vector<G4String> _options;
};

// ====================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class G4MPIscorerMerger
G4ScoringManager* scoringManager;
unsigned int commSize;
unsigned int destinationRank;
MPI::Intracomm comm;
MPI_Comm comm;
G4int verbose;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ class G4VUserMPIrunMerger
virtual void Pack() = 0;
virtual G4Run* UnPack() = 0;

void InputUserData(/*const*/ void* input_data, const MPI::Datatype& dt, int count)
void InputUserData(/*const*/ void* input_data, const MPI_Datatype& dt, int count)
{
input_userdata.push_back(const_registered_data{input_data, dt, count});
}
void OutputUserData(void* input_data, const MPI::Datatype& dt, int count)
void OutputUserData(void* input_data, const MPI_Datatype& dt, int count)
{
output_userdata.push_back(registered_data{input_data, dt, count});
}

// void GetUserData(void* output_data,const MPI::Datatype& dt, int count);
// void GetUserData(void* output_data,const MPI_Datatype& dt, int count);

void SetupOutputBuffer(char* buff, G4int size, G4int position)
{
Expand Down Expand Up @@ -91,7 +91,7 @@ class G4VUserMPIrunMerger
unsigned int destinationRank;
G4Run* run;
unsigned int commSize;
MPI::Intracomm COMM_G4COMMAND_;
MPI_Comm COMM_G4COMMAND_;
G4int verbose;
long bytesSent;

Expand All @@ -103,7 +103,7 @@ class G4VUserMPIrunMerger
// const_registered_data(const_registered_data&&) = default;
// const_registered_data& operator=(const_registered_data&&) = default;
/*const*/ void* p_data;
/*const*/ MPI::Datatype dt;
/*const*/ MPI_Datatype dt;
/*const*/ int count;
};
std::vector<const_registered_data> input_userdata;
Expand All @@ -114,7 +114,7 @@ class G4VUserMPIrunMerger
registered_data(const registered_data&) = default;
registered_data& operator=(const registered_data&) = default;
void* p_data;
/*const*/ MPI::Datatype dt;
/*const*/ MPI_Datatype dt;
/*const*/ int count;
};
std::vector<registered_data> output_userdata;
Expand Down
7 changes: 4 additions & 3 deletions examples/extended/parallel/MPI/source/src/G4MPIhistoMerger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ void G4MPIhistoMerger::Merge()
G4cout << "Starting merging of histograms" << G4endl;
}

const MPI::Intracomm* parentComm = G4MPImanager::GetManager()->GetComm();
MPI::Intracomm comm = parentComm->Dup();
const MPI_Comm* parentComm = G4MPImanager::GetManager()->GetComm();
MPI_Comm comm;
MPI_Comm_dup(*parentComm, &comm);

G4bool verbose = (verboseLevel > 1);
G4int tag = G4MPImanager::kTAG_HISTO;
Expand All @@ -68,5 +69,5 @@ void G4MPIhistoMerger::Merge()
if (verboseLevel > 0) {
G4cout << "End merging of histograms" << G4endl;
}
comm.Free();
MPI_Comm_free(&comm);
}
Loading