Skip to content

Instantly share code, notes, and snippets.

@krrg
Created October 20, 2015 16:05
Show Gist options
  • Save krrg/d7709270e7ba80c7f408 to your computer and use it in GitHub Desktop.
Save krrg/d7709270e7ba80c7f408 to your computer and use it in GitHub Desktop.
Example of using MPI Split
#include <mpi.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
MPI::Init_thread(MPI_THREAD_FUNNELED);
MPI::Intracomm comm = MPI_COMM_WORLD;
int rank = comm.Get_rank();
int size = comm.Get_size();
int myColor = rank % 3;
MPI::Intracomm comm2 = comm.Split(myColor, rank);
comm2.Bcast(&rank, 1, MPI::INT, 0);
cout << "My root is " << rank << ", my local rank is " << comm2.Get_rank() << " and my global rank is " << comm.Get_rank() << endl;
MPI_Finalize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment