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 1 commit
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
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
2 changes: 1 addition & 1 deletion examples/extended/parallel/MPI/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ project(${_projname})

cmake_minimum_required(VERSION 3.16...3.27)
find_package(MPI REQUIRED)
find_package(Geant4 10.2.0 REQUIRED)
find_package(Geant4 REQUIRED)
include(${Geant4_USE_FILE})

#------------------------------------------------------------------------------
Expand Down
11 changes: 9 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 All @@ -153,11 +157,12 @@ class G4MPImanager
G4bool is_slave_;
G4bool is_extra_worker_;
G4int rank_;
G4int provided_;
G4int size_; // processing comm size
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 +193,8 @@ class G4MPImanager
// parallel parameters
G4double master_weight_;
G4int nof_extra_workers_;

std::vector<G4String> _options;
};

// ====================================================================
Expand Down
27 changes: 14 additions & 13 deletions examples/extended/parallel/MPI/source/include/G4MPIscorerMerger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license. These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * institutes, nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
Expand Down Expand Up @@ -103,8 +103,9 @@ class G4MPIscorerMerger
G4ScoringManager* scoringManager;
unsigned int commSize;
unsigned int destinationRank;
MPI::Intracomm comm;
MPI_Comm comm; // Changed from MPI::Intracomm to MPI_Comm
G4int verbose;
void G4mpi_barrier(MPI_Comm* comm) {MPI_Barrier(*comm);};
};

#endif // G4MPISCORERMERGER_HH
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;// = parentComm->Dup();
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