Skip to content

Instantly share code, notes, and snippets.

@tomMoral
Created October 8, 2017 13:56
Show Gist options
  • Save tomMoral/cbb6047eeeea74e3682850ce41d2ae1c to your computer and use it in GitHub Desktop.
Save tomMoral/cbb6047eeeea74e3682850ce41d2ae1c to your computer and use it in GitHub Desktop.
#include <mpi.h>
#include <iostream>
using namespace MPI;
using namespace std;
int main(int argc, char**argv) {
//Initiate the MPI API
Init(argc, argv);
// Get the communicator and the Process API
Intercomm parentComm = Comm::Get_parent();
int rank = parentComm.Get_rank();
int size = parentComm.Get_size();
cout << "Started worker rank: " << rank << "/" << size <<endl;
if(rank == 0)
cout << "Root comm size: " << parentComm.Get_remote_size() << endl;
parentComm.Barrier();
cout << rank << " - Barrier1: ok" << endl;
parentComm.Barrier();
cout << rank << " - Barrier2: ok" << endl;
parentComm.Barrier();
cout << rank << " - Barrier3: ok" << endl;
parentComm.Barrier();
cout << rank << " - Barrier4: ok" << endl;
parentComm.Barrier();
cout << rank << " - Barrier5: ok" << endl;
parentComm.Disconnect();
Finalize();
if(Is_finalized())
return 0;
return 1;
}
#include <mpi.h>
#include <iostream>
using namespace MPI;
using namespace std;
int main(int argc, char**argv) {
Init(argc, argv);
Intercomm comm = COMM_WORLD.Spawn(
"./child_barriers", NULL, 2, INFO_NULL, 0);
cout << "Remote size root: " << comm.Get_remote_size() << endl;
cout << "Barrier" << endl;
comm.Barrier();
cout << "Barrier1: ok" << endl;
comm.Barrier();
cout << "Barrier2: ok" << endl;
comm.Barrier();
cout << "Barrier3: ok" << endl;
comm.Barrier();
cout << "Barrier4: ok" << endl;
comm.Barrier();
cout << "Barrier5: ok" << endl;
comm.Disconnect();
Finalize();
}
EXECS=child_barriers main_barriers
all: ${EXECS}
child_barriers:
mpic++ -o child_barriers child_barriers.cpp
main_barriers:
mpic++ -o main_barriers main_barriers.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment