70 int task, this_node, first_task_in_this_node;
71 int first_index, rank_in_node, tasks_in_node;
72 char name[MPI_MAX_PROCESSOR_NAME];
74 node_data loc_node, *list_of_nodes;
76 static bool system_compare_hostname(
const node_data &a,
const node_data &b)
78 int res = strcmp(a.name, b.name);
83 return a.task < b.task;
86 static bool system_compare_first_task(
const node_data &a,
const node_data &b)
88 if(a.first_task_in_this_node < b.first_task_in_this_node)
90 if(a.first_task_in_this_node > b.first_task_in_this_node)
92 return a.task < b.task;
95 static bool system_compare_task(
const node_data &a,
const node_data &b) {
return a.task < b.task; }
100 int len, nodes, i, no, rank, first_index;
102 MPI_Get_processor_name(loc_node.name, &len);
105 list_of_nodes = (node_data *)malloc(
106 sizeof(node_data) *
NTask);
108 MPI_Allgather(&loc_node,
sizeof(node_data), MPI_BYTE, list_of_nodes,
sizeof(node_data), MPI_BYTE,
Communicator);
110 std::sort(list_of_nodes, list_of_nodes +
NTask, system_compare_hostname);
112 list_of_nodes[0].first_task_in_this_node = list_of_nodes[0].task;
114 for(i = 1, nodes = 1; i <
NTask; i++)
116 if(strcmp(list_of_nodes[i].name, list_of_nodes[i - 1].name) != 0)
118 list_of_nodes[i].first_task_in_this_node = list_of_nodes[i].task;
122 list_of_nodes[i].first_task_in_this_node = list_of_nodes[i - 1].first_task_in_this_node;
125 std::sort(list_of_nodes, list_of_nodes +
NTask, system_compare_first_task);
127 for(i = 0; i <
NTask; i++)
128 list_of_nodes[i].tasks_in_node = 0;
130 for(i = 0, no = 0, rank = 0, first_index = 0; i <
NTask; i++)
132 if(i ? list_of_nodes[i].first_task_in_this_node != list_of_nodes[i - 1].first_task_in_this_node : 0)
139 list_of_nodes[i].first_index = first_index;
140 list_of_nodes[i].this_node = no;
141 list_of_nodes[i].rank_in_node = rank++;
142 list_of_nodes[first_index].tasks_in_node++;
146 int min_count = (1 << 30);
148 for(i = 0; i <
NTask; i++)
150 list_of_nodes[i].tasks_in_node = list_of_nodes[list_of_nodes[i].first_index].tasks_in_node;
152 if(list_of_nodes[i].tasks_in_node > max_count)
153 max_count = list_of_nodes[i].tasks_in_node;
154 if(list_of_nodes[i].tasks_in_node < min_count)
155 min_count = list_of_nodes[i].tasks_in_node;
158 std::sort(list_of_nodes, list_of_nodes +
NTask, system_compare_task);
void mpi_printf(const char *fmt,...)
void determine_compute_nodes(void)
long long SharedMemoryOnNode
void initcomm(MPI_Comm Comm)