Skip to content
Snippets Groups Projects

Free sort indices and task arrays before repartitioning

Merged Peter W. Draper requested to merge free-sorts into master
+ 120
12
Compare changes
  • Side-by-side
  • Inline
Files
+ 67
0
@@ -26,6 +26,7 @@
/* Some standard headers. */
#include <float.h>
#include <stdio.h>
#include <unistd.h>
/* This object's header. */
#include "debug.h"
@@ -450,3 +451,69 @@ void dumpCellRanks(const char *prefix, struct cell *cells_top, int nr_cells) {
}
#endif /* HAVE_MPI */
/**
* @brief parse the process /proc/self/statm file to get the process
* memory use (in KB). Top field in ().
*
* @param size total virtual memory (VIRT)
* @param resident resident non-swapped memory (RES)
* @param share shared (mmap'd) memory (SHR)
* @param trs text (exe) resident set (CODE)
* @param lrs library resident set
* @param drs data+stack resident set (DATA)
* @param dt dirty pages (nDRT)
*/
void getProcMemUse(long *size, long *resident, long *share, long *trs,
long *lrs, long *drs, long *dt) {
/* Open the file. */
FILE *file = fopen("/proc/self/statm", "r");
if (file != NULL) {
int nscan = fscanf(file, "%ld %ld %ld %ld %ld %ld %ld", size, resident,
share, trs, lrs, drs, dt);
if (nscan == 7) {
/* Convert pages into bytes. Usually 4096, but could be 512 on some
* systems so take care in conversion to KB. */
long sz = sysconf(_SC_PAGESIZE);
*size *= sz;
*resident *= sz;
*share *= sz;
*trs *= sz;
*lrs *= sz;
*drs *= sz;
*dt *= sz;
*size /= 1024;
*resident /= 1024;
*share /= 1024;
*trs /= 1024;
*lrs /= 1024;
*drs /= 1024;
*dt /= 1024;
} else {
error("Failed to read sufficient fields from /proc/self/statm");
}
fclose(file);
} else {
error("Failed to open /proc/self/statm");
}
}
/**
* @brief Print the current memory use of the process. A la "top".
*/
void printProcMemUse() {
long size;
long resident;
long share;
long trs;
long lrs;
long drs;
long dt;
getProcMemUse(&size, &resident, &share, &trs, &lrs, &drs, &dt);
printf("## VIRT = %ld , RES = %ld , SHR = %ld , CODE = %ld, DATA = %ld\n",
size, resident, share, trs, drs);
fflush(stdout);
}
Loading