CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MPIService.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 #include <mpi.h>
4 
10 
11 namespace {
12  const char* const mpi_thread_support_level[] = {
13  "MPI_THREAD_SINGLE", // only one thread will execute (the process is single-threaded)
14  "MPI_THREAD_FUNNELED", // only the thread that called MPI_Init_thread will make MPI calls
15  "MPI_THREAD_SERIALIZED", // only one thread will make MPI library calls at one time
16  "MPI_THREAD_MULTIPLE" // multiple threads may call MPI at once with no restrictions
17  };
18 }
19 
20 class MPIService {
21 public:
23  ~MPIService();
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 };
27 
29  // initializes the MPI execution environment, requesting multi-threading support
30  int provided;
31  MPI_Init_thread(nullptr, nullptr, MPI_THREAD_MULTIPLE, &provided);
32  if (provided < MPI_THREAD_MULTIPLE) {
33  throw cms::Exception("UnsupportedFeature")
34  << "CMSSW requires the " << mpi_thread_support_level[MPI_THREAD_MULTIPLE]
35  << " multithreading support level, but the MPI library provides only the " << mpi_thread_support_level[provided]
36  << " level.";
37  } else {
38  edm::LogInfo log("MPIService");
39 
40  // get the number of processes
41  int world_size;
42  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
43  log << "MPI_COMM_WORLD size: " << world_size << '\n';
44 
45  // get the rank of the process
46  int world_rank;
47  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
48  log << "MPI_COMM_WORLD rank: " << world_rank << '\n';
49 
50  // get the name of the processor
51  char processor_name[MPI_MAX_PROCESSOR_NAME];
52  int name_len;
53  MPI_Get_processor_name(processor_name, &name_len);
54  log << "MPI processor name: " << processor_name << '\n';
55 
56  log << "The MPI library provides the " << mpi_thread_support_level[provided] << " multithreading support level\n";
57  log << "MPI successfully initialised";
58  }
59 }
60 
62  // terminate the MPI execution environment
63  MPI_Finalize();
64 }
65 
68  descriptions.add("MPIService", desc);
69  descriptions.setComment(R"(This Service provides a common interface to MPI configuration for the CMSSW job.)");
70 }
71 
static std::vector< std::string > checklist log
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
Definition: ServiceMaker.h:100
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MPIService.cc:66
void setComment(std::string const &value)
MPIService(edm::ParameterSet const &config)
Definition: MPIService.cc:28
void add(std::string const &label, ParameterSetDescription const &psetDescription)
tuple config
parse the configuration file