Creating MPI communicators for reading files -


i need mpi communicators, subject relatively new.

i have mpi code reading input several input files. every process read @ least 1 file, read more one. every file read.

i need create communicator each file. let's example processes 0, 1, , 2 read file "a.dat", processes 2, 3, , 4 read file "b.dat", , processes 4, 5, , 6 read "c.dat". (in practice there many more processes , files.) need 3 communicators. first should contain procs 0, 1, , 2; second 2, 3, , 4; third 4, 5, , 6. i'm rather @ loss how this. know how?

its possible split larger communicator smaller communicators of preferable size:

#include <mpi.h> #include <stdio.h>  int main(int argc, char** argv) {     // initialize mpi environment     mpi_init(null, null);      // rank , size in mpi_comm_world communicator     int world_rank, world_size;     mpi_comm_rank(mpi_comm_world, &world_rank);     mpi_comm_size(mpi_comm_world, &world_size);      int color = world_rank / 4; //4 process (colors) each communicator      mpi_comm row_comm;      /*      first argument communicator used basis new communicators.      second argument determines new communicator each processes belong.      third argument determines ordering (rank) within each new communicator...      process passes in smallest value third argument rank 0, next smallest rank 1, , on.      final argument returns new communicator user.      */     mpi_comm_split(mpi_comm_world, color, world_rank, &row_comm);      int row_rank, row_size;     mpi_comm_rank(row_comm, &row_rank);     mpi_comm_size(row_comm, &row_size);      printf("world rank/size: %d/%d \t row rank/size: %d/%d\n",            world_rank, world_size, row_rank, row_size);      mpi_comm_free(&row_comm);      // finalize mpi environment.     mpi_finalize(); } 

or create groups (more flexible way)

#include <mpi.h> #include <stdio.h>  int main(int argc, char** argv) {     // initialize mpi environment     mpi_init(null, null);      // rank , size in original communicator     int world_rank, world_size;     mpi_comm_rank(mpi_comm_world, &world_rank);     mpi_comm_size(mpi_comm_world, &world_size);      // group of processes in mpi_comm_world     mpi_group world_group;     mpi_comm_group(mpi_comm_world, &world_group);      int prime_group_size = 6;     const int ranks[6] = {2, 3, 5, 7, 11, 13};      // construct group containing of prime ranks in world_group     mpi_group prime_group;     mpi_group_incl(world_group, prime_group_size, ranks, &prime_group);      // create new communicator based on group     mpi_comm prime_comm;     mpi_comm_create_group(mpi_comm_world, prime_group, 0, &prime_comm);      int prime_rank = -1, prime_size = -1;     // if rank isn't in new communicator,     // mpi_comm_null. using mpi_comm_null mpi_comm_rank or     // mpi_comm_size erroneous     if (mpi_comm_null != prime_comm) {         mpi_comm_rank(prime_comm, &prime_rank);         mpi_comm_size(prime_comm, &prime_size);          printf("world rank/size: %d/%d \t prime rank/size: %d/%d\n",                world_rank, world_size, prime_rank, prime_size);          mpi_group_free(&prime_group);         mpi_comm_free(&prime_comm);     }       mpi_group_free(&world_group);      // finalize mpi environment.     mpi_finalize(); } 

reference


Comments