2 * get the information of which thread are on the same node
11 int split_comm_intra_node(MPI_Comm comm, MPI_Comm* comm_intra, int key) {
12 // collect processor names
13 char name[MPI_MAX_PROCESSOR_NAME];
16 char** names = get_names(comm);
20 MPI_Get_processor_name(name, &len);
21 MPI_Comm_size(comm, &size);
23 if (strcmp(name, names[i]) == 0) {
30 // split the communicator
31 return MPI_Comm_split(comm, color, key, comm_intra);
34 char** get_names(MPI_Comm comm){
35 char name[MPI_MAX_PROCESSOR_NAME];
39 char** friendly_names;
42 MPI_Get_processor_name(name, &len);
43 MPI_Comm_size(comm, &size);
44 friendly_names = malloc(sizeof(char*) * size);
45 names = malloc(sizeof(char) * MPI_MAX_PROCESSOR_NAME * size);
47 MPI_Allgather(name, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names,
48 MPI_MAX_PROCESSOR_NAME, MPI_CHAR, comm);
50 for( i = 0; i < size;i++) friendly_names[i] = &names[MPI_MAX_PROCESSOR_NAME * i];
51 return friendly_names;
54 int* get_index(MPI_Comm comm, MPI_Comm comm_intra){
59 MPI_Comm_rank(comm_intra, &rank);
60 MPI_Comm_size(comm, &size);
61 index = (int*)malloc(sizeof(int) * size);
62 MPI_Allgather(&rank, 1, MPI_INT, index, 1, MPI_INT, comm);