@@ -58,6 +58,7 @@ class MPISource : public edm::ProducerSourceBase {
5858 MPI_Comm comm_ = MPI_COMM_NULL;
5959 MPIChannel channel_;
6060 edm::EDPutTokenT<MPIToken> token_;
61+ bool run_local_;
6162
6263 edm::ProcessHistory history_;
6364};
@@ -76,22 +77,37 @@ MPISource::MPISource(edm::ParameterSet const& config, edm::InputSourceDescriptio
7677 // make sure the EDM MPI types are available
7778 EDM_MPI_build_types ();
7879
79- // open a server-side port
80- MPI_Open_port (MPI_INFO_NULL, port_);
81-
82- // publish the port under the name "server"
83- MPI_Info port_info;
84- MPI_Info_create (&port_info);
85- MPI_Info_set (port_info, " ompi_global_scope" , " true" );
86- MPI_Info_set (port_info, " ompi_unique" , " true" );
87- MPI_Publish_name (" server" , port_info, port_);
88-
89- // create an intercommunicator and accept a client connection
90- edm::LogAbsolute (" MPI" ) << " waiting for a connection to the MPI server at port " << port_;
91- MPI_Comm_accept (port_, MPI_INFO_NULL, 0 , MPI_COMM_WORLD, &comm_);
92- channel_ = MPIChannel (comm_, 0 );
80+ // get from parameter set whether remote mpi is used
81+ run_local_ = config.getUntrackedParameter <bool >(" run_local" , false );
82+
83+ edm::LogAbsolute (" MPI" ) << " Running source in " << (run_local_ ? " local" : " remote" ) << " mode." ;
84+
85+ if (run_local_) {
86+ int world_rank;
87+ MPI_Comm_rank (MPI_COMM_WORLD, &world_rank);
88+ std::cout << " MPI Source Rank: " << world_rank << " in MPI_COMM_WORLD" << std::endl;
89+ comm_ = MPI_COMM_WORLD;
90+ channel_ = MPIChannel (comm_, 1 );
91+ } else {
92+ // open a server-side port
93+ MPI_Open_port (MPI_INFO_NULL, port_);
94+
95+ // publish the port under the name "server"
96+ MPI_Info port_info;
97+ MPI_Info_create (&port_info);
98+ MPI_Info_set (port_info, " ompi_global_scope" , " true" );
99+ MPI_Info_set (port_info, " ompi_unique" , " true" );
100+ MPI_Publish_name (" server" , port_info, port_);
101+
102+ // create an intercommunicator and accept a client connection
103+ edm::LogAbsolute (" MPI" ) << " waiting for a connection to the MPI server at port " << port_;
104+
105+ MPI_Comm_accept (port_, MPI_INFO_NULL, 0 , MPI_COMM_WORLD, &comm_);
106+ edm::LogAbsolute (" MPI" ) << " connection accept " ;
107+ channel_ = MPIChannel (comm_, 0 );
108+ }
93109
94- // wait for a client to connect
110+ // // wait for a client to connect
95111 MPI_Status status;
96112 EDM_MPI_Empty_t buffer;
97113 MPI_Recv (&buffer, 1 , EDM_MPI_Empty, MPI_ANY_SOURCE, EDM_MPI_Connect, comm_, &status);
@@ -100,15 +116,17 @@ MPISource::MPISource(edm::ParameterSet const& config, edm::InputSourceDescriptio
100116
101117MPISource::~MPISource () {
102118 // close the intercommunicator
103- MPI_Comm_disconnect (&comm_);
104-
105- // unpublish and close the port
106- MPI_Info port_info;
107- MPI_Info_create (&port_info);
108- MPI_Info_set (port_info, " ompi_global_scope" , " true" );
109- MPI_Info_set (port_info, " ompi_unique" , " true" );
110- MPI_Unpublish_name (" server" , port_info, port_);
111- MPI_Close_port (port_);
119+ if (!run_local_) {
120+ MPI_Comm_disconnect (&comm_);
121+
122+ // unpublish and close the port
123+ MPI_Info port_info;
124+ MPI_Info_create (&port_info);
125+ MPI_Info_set (port_info, " ompi_global_scope" , " true" );
126+ MPI_Info_set (port_info, " ompi_unique" , " true" );
127+ MPI_Unpublish_name (" server" , port_info, port_);
128+ MPI_Close_port (port_);
129+ }
112130}
113131
114132// MPISource::ItemTypeInfo MPISource::getNextItemType() {
@@ -259,6 +277,8 @@ void MPISource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
259277 desc.setComment (" Comunicate with another cmsRun process over MPI." );
260278 edm::ProducerSourceBase::fillDescription (desc);
261279
280+ desc.addOptionalUntracked <bool >(" run_local" );
281+
262282 descriptions.add (" source" , desc);
263283}
264284
0 commit comments