2 * get the information of which thread are on the same node
5 * Authors: Quintin Jean-Noël
13 int split_comm_intra_node(MPI_Comm comm, MPI_Comm* comm_intra, int key) {
14 // collect processor names
15 char name[MPI_MAX_PROCESSOR_NAME];
18 char** names = get_names(comm);
22 MPI_Get_processor_name(name, &len);
23 MPI_Comm_size(comm, &size);
25 if (strcmp(name, names[i]) == 0) {
32 // split the communicator
33 return MPI_Comm_split(comm, color, key, comm_intra);
36 char** get_names(MPI_Comm comm){
37 char name[MPI_MAX_PROCESSOR_NAME];
41 char** friendly_names;
44 MPI_Get_processor_name(name, &len);
45 MPI_Comm_size(comm, &size);
46 friendly_names = malloc(sizeof(char*) * size);
47 names = malloc(sizeof(char) * MPI_MAX_PROCESSOR_NAME * size);
49 MPI_Allgather(name, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names,
50 MPI_MAX_PROCESSOR_NAME, MPI_CHAR, comm);
52 for( i = 0; i < size;i++) friendly_names[i] = &names[MPI_MAX_PROCESSOR_NAME * i];
53 return friendly_names;
56 int* get_index(MPI_Comm comm, MPI_Comm comm_intra){
61 MPI_Comm_rank(comm_intra, &rank);
62 MPI_Comm_size(comm, &size);
63 index = (int*)malloc(sizeof(int) * size);
64 MPI_Allgather(&rank, 1, MPI_INT, index, 1, MPI_INT, comm);