119 const dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
124 char nodename[MPI_MAX_PROCESSOR_NAME];
125 int namelength, nodehash;
126 int rank, nProcs, nodeRank, interRank;
128 const double GiB = pow(2,30);
130 std::hash<std::string> hasher;
135 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
136 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
139 MPI_Get_processor_name(nodename,&namelength);
140 nodehash=(int)(hasher(std::string(nodename)) % std::numeric_limits<int>::max());
143 MPI_Comm_split(MPI_COMM_WORLD, nodehash, rank, &nodeComm);
144 MPI_Comm_rank(nodeComm,&nodeRank);
146 MPI_Comm_split(MPI_COMM_WORLD, nodeRank, rank, &interComm);
147 MPI_Comm_rank(interComm, &interRank);
148 MPI_Comm_size(interComm, &nNodes);
152 double total_mem_proc = 0;
153 double min_free,max_free;
154 const int numberOfParameters = 1;
155 MPI_Reduce( &mem_proc_free, &total_mem_proc, numberOfParameters, MPI_DOUBLE, MPI_SUM, 0, interComm );
156 MPI_Reduce( &mem_proc_free, &min_free, numberOfParameters, MPI_DOUBLE, MPI_MIN,
MASTER_RANK, MPI_COMM_WORLD );
157 MPI_Reduce( &mem_proc_free, &max_free, numberOfParameters, MPI_DOUBLE, MPI_MAX,
MASTER_RANK, MPI_COMM_WORLD );
159 char reportstring[512];
160 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g %-21s (GiB/node; avg, min, max, sum): %-8.3g %-8.3g %-8.3g %-8.3g on %i nodes\n",
161 P::tstep,
P::t,
"Free", total_mem_proc/nNodes/GiB, min_free/GiB, max_free/GiB, total_mem_proc/GiB, nNodes);
166 if (PAPI_library_init(PAPI_VER_CURRENT) == PAPI_VER_CURRENT) {
167 PAPI_dmem_info_t dmem;
168 PAPI_get_dmem_info(&dmem);
169 double mem_papi[4] = {};
170 double node_mem_papi[4] = {};
171 double sum_mem_papi[4];
172 double min_mem_papi[4];
173 double max_mem_papi[4];
175 mem_papi[0] = dmem.high_water_mark * 1024;
176 mem_papi[1] = dmem.resident * 1024 + extra_bytes;
177 mem_papi[2] = dmem.resident * 1024;
178 mem_papi[3] = extra_bytes;
180 MPI_Reduce(mem_papi, node_mem_papi, 4, MPI_DOUBLE, MPI_SUM, 0, nodeComm);
184 MPI_Reduce(node_mem_papi, sum_mem_papi, 4, MPI_DOUBLE, MPI_SUM, 0, interComm);
185 MPI_Reduce(node_mem_papi, min_mem_papi, 4, MPI_DOUBLE, MPI_MIN, 0, interComm);
186 MPI_Reduce(node_mem_papi, max_mem_papi, 4, MPI_DOUBLE, MPI_MAX, 0, interComm);
187 if (max_mem_papi[3] != 0.0) {
188 logFile <<
"(MEM) Estimating increased high water mark from refinement" << std::endl;
190 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g %-21s (GiB/node; avg, min, max, sum): %-8.3g %-8.3g %-8.3g %-8.3g on %i nodes\n",
191 P::tstep,
P::t,
"Resident", sum_mem_papi[2]/nNodes/GiB, min_mem_papi[2]/GiB, max_mem_papi[2]/GiB, sum_mem_papi[2]/GiB, nNodes);
193 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g %-21s (GiB/node; avg, min, max, sum): %-8.3g %-8.3g %-8.3g %-8.3g on %i nodes\n",
194 P::tstep,
P::t,
"High water mark \U0001F30A ", sum_mem_papi[0]/nNodes/GiB, min_mem_papi[0]/GiB, max_mem_papi[0]/GiB, sum_mem_papi[0]/GiB, nNodes);
196 if (max_mem_papi[3] != 0.0) {
197 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g %-21s (GiB/node; avg, min, max, sum): %-8.3g %-8.3g %-8.3g %-8.3g on %i nodes\n",
198 P::tstep,
P::t,
"Resident with refines", sum_mem_papi[1]/nNodes/GiB, min_mem_papi[1]/GiB, max_mem_papi[1]/GiB, sum_mem_papi[1]/GiB, nNodes);
211 const std::vector<CellID> remote_cells = mpiGrid.get_remote_cells_on_process_boundary();
223 for(
unsigned int i=0;
i<cells.size();
i++){
226 mem[0] += mpiGrid[cells[
i]]->largestvmesh *
WID3 *
sizeof(
Realf);
228 mem[0] += mpiGrid[cells[
i]]->get_cell_memory_size();
230 mem[3] += mpiGrid[cells[
i]]->get_cell_memory_capacity();
233 for(
unsigned int i=0;
i<remote_cells.size();
i++){
234 if(mpiGrid[remote_cells[
i]] != NULL) {
235 mem[1] += mpiGrid[remote_cells[
i]]->get_cell_memory_size();
236 mem[4] += mpiGrid[remote_cells[
i]]->get_cell_memory_capacity();
240 mem[2] = mem[0] + mem[1];
241 mem[5] = mem[3] + mem[4];
244 MPI_Reduce(mem, sum_mem, 6, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
250 } max_mem[3],mem_usage_loc[3],min_mem[3];
251 for(uint
i = 0;
i<3;
i++){
252 mem_usage_loc[
i].val = mem[
i + 3];
253 mem_usage_loc[
i].rank = rank;
256 MPI_Reduce(mem_usage_loc, max_mem, 3, MPI_DOUBLE_INT, MPI_MAXLOC, 0, MPI_COMM_WORLD);
257 MPI_Reduce(mem_usage_loc, min_mem, 3, MPI_DOUBLE_INT, MPI_MINLOC, 0, MPI_COMM_WORLD);
260 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g %-21s (GiB/rank; avg, min, max, sum): %-8.3g %-8.3g %-8.3g %-8.3g min rank %i max rank %i\n",
261 P::tstep,
P::t,
"Local cells capacity", sum_mem[3]/nProcs/GiB, min_mem[0].val/GiB, max_mem[0].val/GiB, sum_mem[3]/GiB, min_mem[0].rank, max_mem[0].rank);
263 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g %-21s (GiB/rank; avg, min, max, sum): %-8.3g %-8.3g %-8.3g %-8.3g min rank %i max rank %i\n",
264 P::tstep,
P::t,
"Remote cells capacity", sum_mem[4]/nProcs/GiB, min_mem[1].val/GiB, max_mem[1].val/GiB, sum_mem[4]/GiB, min_mem[1].rank, max_mem[1].rank);
266 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g %-21s (GiB/rank; avg, min, max, sum): %-8.3g %-8.3g %-8.3g %-8.3g min rank %i max rank %i\n",
267 P::tstep,
P::t,
"Total cells capacity", sum_mem[5]/nProcs/GiB, min_mem[2].val/GiB, max_mem[2].val/GiB, sum_mem[5]/GiB, min_mem[2].rank, max_mem[2].rank);
270 snprintf(reportstring,512,
"(MEM) tstep %i t %.3g Total size and capacity of SpatialCells (GiB): %-8.3g %-8.3g\n",
276 MPI_Comm_free(&interComm);
277 MPI_Comm_free(&nodeComm);