[araim1@tara-fe1 ~]$ top
top - 01:19:53 up 79 days, 12:52, 4 users, load average: 0.00, 0.00, 0.00 Tasks: 232 total, 1 running, 230 sleeping, 0 stopped, 1 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 99.5%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 49433548k total, 35805616k used, 13627932k free, 747232k buffers Swap: 8385888k total, 0k used, 8385888k free, 32890968k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 28336 araim1 15 0 10976 1148 776 R 0.3 0.0 0:00.02 top 1 root 15 0 10348 696 584 S 0.0 0.0 0:01.45 init 2 root RT -5 0 0 0 S 0.0 0.0 0:01.91 migration/0 3 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 5 root RT -5 0 0 0 S 0.0 0.0 0:01.39 migration/1 6 root 34 19 0 0 0 S 0.0 0.0 0:00.05 ksoftirqd/1 7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1 8 root RT -5 0 0 0 S 0.0 0.0 0:01.04 migration/2 9 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/2 10 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/2 11 root RT -5 0 0 0 S 0.0 0.0 0:01.66 migration/3 12 root 34 19 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/3 13 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/3 14 root RT -5 0 0 0 S 0.0 0.0 0:07.36 migration/4 15 root 34 19 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/4 16 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/4 17 root RT -5 0 0 0 S 0.0 0.0 0:00.50 migration/5 18 root 34 19 0 0 0 S 0.0 0.0 0:00.15 ksoftirqd/5 19 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/5 20 root RT -5 0 0 0 S 0.0 0.0 0:00.12 migration/6 21 root 34 19 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/6
top - 01:30:57 up 79 days, 13:03, 4 users, load average: 0.00, 0.00, 0.00 Tasks: 232 total, 1 running, 230 sleeping, 0 stopped, 1 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 99.9%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 49433548k total, 35805656k used, 13627892k free, 747232k buffers Swap: 8385888k total, 0k used, 8385888k free, 32891308k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 28336 araim1 15 0 10976 1152 780 R 0.3 0.0 0:01.47 top 25694 araim1 15 0 99196 1768 976 S 0.0 0.0 0:02.60 sshd 25695 araim1 15 0 66260 3672 1184 S 0.0 0.0 0:01.67 bash
top - 01:32:09 up 79 days, 13:05, 4 users, load average: 0.00, 0.00, 0.00 Tasks: 232 total, 1 running, 230 sleeping, 0 stopped, 1 zombie Cpu0 : 0.0%us, 0.1%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu1 : 0.1%us, 0.1%sy, 0.0%ni, 99.5%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Cpu2 : 0.1%us, 0.1%sy, 0.0%ni, 99.5%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st Cpu3 : 0.2%us, 0.1%sy, 0.0%ni, 99.5%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Cpu4 : 0.1%us, 0.0%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu5 : 0.1%us, 0.3%sy, 0.0%ni, 99.6%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st Cpu6 : 0.0%us, 0.0%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu7 : 0.1%us, 0.0%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 49433548k total, 35805832k used, 13627716k free, 747232k buffers Swap: 8385888k total, 0k used, 8385888k free, 32891340k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 25694 araim1 15 0 99196 1768 976 S 0.0 0.0 0:02.60 sshd 25695 araim1 15 0 66260 3672 1184 S 0.0 0.0 0:01.67 bash 28336 araim1 15 0 10976 1152 780 R 0.0 0.0 0:01.61 top
[araim1@tara-fe1 ~]$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 26 model name : Intel(R) Xeon(R) CPU X5550 @ 2.67GHz stepping : 5 cpu MHz : 1596.000 cache size : 8192 KB physical id : 0 siblings : 4 core id : 0 cpu cores : 4 apicid : 0 fpu : yes fpu_exception : yes cpuid level : 11 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx rdtscp lm constant_tsc ida nonstop_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm bogomips : 5333.69 clflush size : 64 cache_alignment : 64 address sizes : 40 bits physical, 48 bits virtual power management: [8] ... (7 other cores are displayed as well) ...
[araim1@tara-fe1 ~]$ cat /proc/meminfo MemTotal: 49433548 kB MemFree: 13626952 kB Buffers: 747232 kB Cached: 32891628 kB SwapCached: 0 kB Active: 4659696 kB Inactive: 29089212 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 49433548 kB LowFree: 13626952 kB SwapTotal: 8385888 kB SwapFree: 8385888 kB Dirty: 136 kB Writeback: 0 kB AnonPages: 109404 kB Mapped: 18788 kB Slab: 1922440 kB PageTables: 11608 kB NFS_Unstable: 0 kB Bounce: 0 kB CommitLimit: 33102660 kB Committed_AS: 305584 kB VmallocTotal: 34359738367 kB VmallocUsed: 270516 kB VmallocChunk: 34359467755 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 Hugepagesize: 2048 kB
[araim1@tara-fe1 check_memory_parallel]$ cat /proc/self/status Name: cat State: R (running) SleepAVG: 88% Tgid: 28665 Pid: 28665 PPid: 25695 TracerPid: 0 Uid: 28398 28398 28398 28398 Gid: 1057 1057 1057 1057 FDSize: 256 Groups: 700 701 1057 32296 1104637136 VmPeak: 58904 kB VmSize: 58904 kB VmLck: 0 kB VmHWM: 476 kB VmRSS: 476 kB VmData: 164 kB VmStk: 84 kB VmExe: 20 kB VmLib: 1444 kB VmPTE: 40 kB StaBrk: 04eed000 kB Brk: 04f0e000 kB StaStk: 7fff9cdf3b70 kB Threads: 1 SigQ: 0/409600 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 Cpus_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000ffff Mems_allowed: 00000000,00000003
[araim1@tara-fe1 ~]$ cat /proc/self/status | egrep 'VmSize|VmRSS' VmSize: 58908 kB VmRSS: 468 kB
#include "memory.h" /* * Look for lines in the procfile contents like: * VmRSS: 5560 kB * VmSize: 5560 kB * * Grab the number between the whitespace and the "kB" * If 1 is returned in the end, there was a serious problem * (we could not find one of the memory usages) */ int get_memory_usage_kb(long* vmrss_kb, long* vmsize_kb) { /* Get the the current process' status file from the proc filesystem */ FILE* procfile = fopen("/proc/self/status", "r"); long to_read = 8192; char buffer[to_read]; int read = fread(buffer, sizeof(char), to_read, procfile); fclose(procfile); short found_vmrss = 0; short found_vmsize = 0; char* search_result; /* Look through proc status contents line by line */ char delims[] = "\n"; char* line = strtok(buffer, delims); while (line != NULL && (found_vmrss == 0 || found_vmsize == 0) ) { search_result = strstr(line, "VmRSS:"); if (search_result != NULL) { sscanf(line, "%*s %ld", vmrss_kb); found_vmrss = 1; } search_result = strstr(line, "VmSize:"); if (search_result != NULL) { sscanf(line, "%*s %ld", vmsize_kb); found_vmsize = 1; } line = strtok(NULL, delims); } return (found_vmrss == 1 && found_vmsize == 1) ? 0 : 1; }
#include <stdlib.h> #include <stdio.h> #include <string.h> int get_memory_usage_kb(long* vmrss_kb, long* vmsize_kb);
#include "memory.h" int main() { int n = 20; int entrySize = 10000000; int* buffer[n]; long vmrss, vmsize; for (int i = 0; i < n; i++) { buffer[i] = malloc( entrySize * sizeof(int) ); if (!buffer[i]) { printf("Couldn't allocate memory!\n"); exit(1); } for (int j = 0; j < entrySize; j++) { buffer[i][j] = 0; } get_memory_usage_kb(&vmrss, &vmsize); printf("%2d: Current memory usage: VmRSS = %6ld KB, VmSize = %6ld KB\n", i, vmrss, vmsize); } return 0; }
PROGNAME := check_memory main: memory.h mpicc $(PROGNAME).c memory.c -o $(PROGNAME) clean: rm -f $(PROGNAME) *.o
[araim1@tara-fe1 check_memory_serial]$ make mpicc check_memory.c memory.c -o check_memory check_memory.c: memory.c: [araim1@tara-fe1 check_memory_serial]$ ./check_memory 0: Current memory usage: VmRSS = 40260 KB, VmSize = 68052 KB 1: Current memory usage: VmRSS = 79432 KB, VmSize = 107120 KB 2: Current memory usage: VmRSS = 118492 KB, VmSize = 146180 KB 3: Current memory usage: VmRSS = 157556 KB, VmSize = 185244 KB 4: Current memory usage: VmRSS = 196620 KB, VmSize = 224304 KB 5: Current memory usage: VmRSS = 235680 KB, VmSize = 263368 KB 6: Current memory usage: VmRSS = 274744 KB, VmSize = 302432 KB 7: Current memory usage: VmRSS = 313804 KB, VmSize = 341492 KB 8: Current memory usage: VmRSS = 352868 KB, VmSize = 380556 KB 9: Current memory usage: VmRSS = 391932 KB, VmSize = 419620 KB 10: Current memory usage: VmRSS = 430992 KB, VmSize = 458680 KB 11: Current memory usage: VmRSS = 470056 KB, VmSize = 497744 KB 12: Current memory usage: VmRSS = 509120 KB, VmSize = 536804 KB 13: Current memory usage: VmRSS = 548180 KB, VmSize = 575868 KB 14: Current memory usage: VmRSS = 587244 KB, VmSize = 614932 KB 15: Current memory usage: VmRSS = 626304 KB, VmSize = 653992 KB 16: Current memory usage: VmRSS = 665368 KB, VmSize = 693056 KB 17: Current memory usage: VmRSS = 704432 KB, VmSize = 732120 KB 18: Current memory usage: VmRSS = 743492 KB, VmSize = 771180 KB 19: Current memory usage: VmRSS = 782556 KB, VmSize = 810244 KB [araim1@tara-fe1 check_memory_serial]$
#include "memory_parallel.h" int get_cluster_memory_usage_kb(long* vmrss_per_process, long* vmsize_per_process, int root, int np) { long vmrss_kb; long vmsize_kb; int ret_code = get_memory_usage_kb(&vmrss_kb, &vmsize_kb); if (ret_code != 0) { printf("Could not gather memory usage!\n"); return ret_code; } MPI_Gather(&vmrss_kb, 1, MPI_UNSIGNED_LONG, vmrss_per_process, 1, MPI_UNSIGNED_LONG, root, MPI_COMM_WORLD); MPI_Gather(&vmsize_kb, 1, MPI_UNSIGNED_LONG, vmsize_per_process, 1, MPI_UNSIGNED_LONG, root, MPI_COMM_WORLD); return 0; } int get_global_memory_usage_kb(long* global_vmrss, long* global_vmsize, int np) { long vmrss_per_process[np]; long vmsize_per_process[np]; int ret_code = get_cluster_memory_usage_kb(vmrss_per_process, vmsize_per_process, 0, np); if (ret_code != 0) { return ret_code; } *global_vmrss = 0; *global_vmsize = 0; for (int i = 0; i < np; i++) { *global_vmrss += vmrss_per_process[i]; *global_vmsize += vmsize_per_process[i]; } return 0; }
#include <mpi.h> #include <memory.h> int get_cluster_memory_usage_kb(long* vmrss_per_process, long* vmsize_per_process, int root, int np); int get_global_memory_usage_kb(long* global_vmrss, long* global_vmsize, int np);
#include <mpi.h> #include <stdio.h> #include <unistd.h> #include "memory_parallel.h" int main (int argc, char *argv[]) { int id, np; char processor_name[MPI_MAX_PROCESSOR_NAME]; char hostname[MPI_MAX_PROCESSOR_NAME]; int processor_name_len; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &np); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Get_processor_name(processor_name, &processor_name_len); printf("Number_of_processes=%03d, My_rank=%03d, processor_name=%5s\n", np, id, processor_name); int entrySize = 1000000 + id * 100000; long* l_buffer[entrySize]; for (int j = 0; j < entrySize; j++) { l_buffer[j] = 0; } long vmrss_per_process[np]; long vmsize_per_process[np]; get_cluster_memory_usage_kb(vmrss_per_process, vmsize_per_process, 0, np); if (id == 0) { for (int k = 0; k < np; k++) { printf("Process %03d: VmRSS = %6ld KB, VmSize = %6ld KB\n", k, vmrss_per_process[k], vmsize_per_process[k]); } } long global_vmrss, global_vmsize; get_global_memory_usage_kb(&global_vmrss, &global_vmsize, np); if (id == 0) { printf("Global memory usage: VmRSS = %6ld KB, VmSize = %6ld KB\n", global_vmrss, global_vmsize); } MPI_Finalize(); return 0; }
PROGNAME := check_memory main: memory.h memory_parallel.h mpicc $(PROGNAME).c memory.c memory_parallel.c -o $(PROGNAME) clean: rm -f $(PROGNAME) *.o
#!/bin/bash #SBATCH --job-name=MPI_check_memory #SBATCH --output=slurm.out #SBATCH --error=slurm.err #SBATCH --partition=develop #SBATCH --nodes=2 #SBATCH --ntasks-per-node=2 srun ./check_memory
[araim1@tara-fe1 check_memory_parallel]$ make mpicc check_memory.c memory.c memory_parallel.c -o check_memory check_memory.c: memory.c: memory_parallel.c: [araim1@tara-fe1 check_memory_parallel]$ sbatch mvapich2.slurm sbatch: Submitted batch job 1581 [araim1@tara-fe1 check_memory_parallel]$ cat slurm.out Number_of_processes=004, My_rank=003, processor_name= n2 Number_of_processes=004, My_rank=001, processor_name= n1 Number_of_processes=004, My_rank=000, processor_name= n1 Process 000: VmRSS = 22996 KB, VmSize = 77268 KB Process 001: VmRSS = 19624 KB, VmSize = 78048 KB Process 002: VmRSS = 24552 KB, VmSize = 78828 KB Process 003: VmRSS = 21196 KB, VmSize = 79612 KB Global memory usage: VmRSS = 88752 KB, VmSize = 314052 KB Number_of_processes=004, My_rank=002, processor_name= n2 [araim1@tara-fe1 check_memory_parallel]$