1 #define TRACE_NAME "MPISentry"
2 #include "artdaq-mpich-plugin/Application/MPISentry.hh"
4 #include "artdaq/DAQdata/Globals.hh"
5 #include "cetlib_except/exception.h"
10 : threading_level_(0), rank_(-1), procs_(0)
12 MPI_Init(argc_ptr, argv_ptr);
17 : threading_level_(0), rank_(-1), procs_(0)
19 MPI_Init_thread(argc_ptr, argv_ptr, threading_level, &threading_level_);
22 std::ostringstream threadresult;
23 threadresult <<
"MPI initialized with requested thread support level of " << threading_level
24 <<
", actual support level = " << threading_level_ <<
".";
26 TLOG(TLVL_DEBUG) << threadresult.str();
28 if (threading_level != threading_level_)
throw cet::exception(
"MPISentry") << threadresult.str();
30 TLOG(TLVL_DEBUG) <<
"size = " << procs_ <<
", rank = " << rank_;
34 MPI_Comm& local_group_comm)
35 : threading_level_(0), rank_(-1), procs_(0)
37 MPI_Init_thread(argc_ptr, argv_ptr, threading_level, &threading_level_);
40 std::ostringstream threadresult;
41 threadresult <<
"MPI initialized with requested thread support level of " << threading_level
42 <<
", actual support level = " << threading_level_ <<
".";
44 TLOG(TLVL_DEBUG) << threadresult.str();
46 if (threading_level != threading_level_)
throw cet::exception(
"MPISentry") << threadresult.str();
48 TLOG(TLVL_DEBUG) <<
"size = " << procs_ <<
", rank = " << rank_;
50 int status = MPI_Comm_split(MPI_COMM_WORLD, type, 0, &local_group_comm);
52 if (status == MPI_SUCCESS)
55 MPI_Comm_rank(local_group_comm, &temp_rank);
57 TLOG(TLVL_DEBUG) <<
"Successfully created local communicator for type " << type <<
", identifier = 0x" << std::hex
58 << local_group_comm << std::dec <<
", rank = " << temp_rank <<
".";
62 std::ostringstream groupcommresult;
63 groupcommresult <<
"Failed to create the local MPI communicator group for "
64 <<
"task type #" << type <<
", status code = " << status <<
".";
65 TLOG(TLVL_ERROR) << groupcommresult.str();
66 throw cet::exception(
"MPISentry") << groupcommresult.str();
78 void artdaq::MPISentry::initialize_()
80 MPI_Comm_size(MPI_COMM_WORLD, &procs_);
81 MPI_Comm_rank(MPI_COMM_WORLD, &rank_);
MPISentry(int *argc_ptr, char ***argv_ptr)
MPISentry Constructor.
int rank() const
Get the MPI rank of the application.
int threading_level() const
Get the actual threading level.
int procs() const
The number of processes in the MPI context.
~MPISentry()
MPISentry Destructor. Calls MPI_Finalize.