12#include "gadgetconfig.h"
14#include <gsl/gsl_rng.h>
23#include <sys/resource.h>
24#include <sys/statvfs.h>
30#include "../data/allvars.h"
31#include "../data/dtypes.h"
32#include "../data/mymalloc.h"
34#include "../logs/logs.h"
35#include "../main/main.h"
36#include "../main/simulation.h"
37#include "../mpi_utils/mpi_utils.h"
38#include "../system/system.h"
51void subdivide_evenly(
long long N,
int pieces,
int index_bin,
long long *first,
int *count)
53 if(N / pieces > INT_MAX)
56 int nbase = N / pieces;
57 int additional = N % pieces;
58 *first = index_bin * ((
long long)nbase) + ((index_bin < additional) ? index_bin : additional);
59 *count = nbase + (index_bin < additional);
64 int nbase = N / pieces;
65 int additional = N % pieces;
66 *first = index_bin * nbase + ((index_bin < additional) ? index_bin : additional);
67 *count = nbase + (index_bin < additional);
72 int nbase = N / pieces;
73 int additional = N % pieces;
75 if(index < additional * (nbase + 1))
76 *bin = index / (nbase + 1);
78 *bin = (index - additional) / nbase;
83#define WALK_N_PIECES 32
84#define WALK_N_SIZE 500
87 int nchunksize = ncount;
97 int *chunked_TargetList = (
int *)
Mem.mymalloc(
"chunked_TargetList", ncount *
sizeof(
int));
98 for(
int n = 0, nextparticle = 0; n < ncount; n++)
100 int i = nextparticle;
102 chunked_TargetList[n] = list[i];
107 if((nextparticle % nchunksize) == 0)
108 nextparticle += (nchunk - 1) * nchunksize;
110 if(nextparticle >= ncount)
113 if(currentchunk < nchunk)
114 nextparticle = currentchunk * nchunksize;
119 for(
int n = 0; n < ncount; n++)
120 list[n] = chunked_TargetList[n];
122 Mem.myfree(chunked_TargetList);
139#if defined(DEBUG_ENABLE_FPU_EXCEPTIONS) && defined(__linux__)
142 extern int feenableexcept(
int __excepts);
143 feenableexcept(FE_DIVBYZERO | FE_INVALID);
152 getrlimit(RLIMIT_CORE, &rlim);
153 rlim.rlim_cur = RLIM_INFINITY;
154 setrlimit(RLIMIT_CORE, &rlim);
160 signal(SIGSEGV, SIG_DFL);
161 signal(SIGBUS, SIG_DFL);
162 signal(SIGFPE, SIG_DFL);
163 signal(SIGINT, SIG_DFL);
172 if((fd = fopen(
"/proc/meminfo",
"r")))
176 if(fgets(buf, 500, fd) != buf)
179 if(bcmp(buf,
"MemTotal", 8) == 0)
181 *MemTotal = atoll(buf + 10);
183 if(strncmp(buf,
"Committed_AS", 12) == 0)
185 *Committed_AS = atoll(buf + 14);
187 if(strncmp(buf,
"SwapTotal", 9) == 0)
189 *SwapTotal = atoll(buf + 11);
191 if(strncmp(buf,
"SwapFree", 8) == 0)
193 *SwapFree = atoll(buf + 10);
199 return (*MemTotal - *Committed_AS);
207 if(statvfs(
"/dev/shm", &buf) == 0)
209 return (1024.0 * (uint64_t)buf.f_bsize * ((uint64_t)(buf.f_bavail))) *
TO_MBYTE_FAC;
217 long long *sizelist, maxsize[7], minsize[7];
219 int i, imem, mintask[7], maxtask[7];
231 for(imem = 0; imem < 7; imem++)
233 sizelist = (
long long *)malloc(
NTask *
sizeof(
long long));
234 MPI_Allgather(&
Mem[imem],
sizeof(
long long), MPI_BYTE, sizelist,
sizeof(
long long), MPI_BYTE,
Communicator);
236 for(i = 1, mintask[imem] = 0, maxtask[imem] = 0, maxsize[imem] = minsize[imem] = sizelist[0], avgsize[imem] = sizelist[0];
239 if(sizelist[i] > maxsize[imem])
241 maxsize[imem] = sizelist[i];
244 if(sizelist[i] < minsize[imem])
246 minsize[imem] = sizelist[i];
249 avgsize[imem] += sizelist[i];
258 "\n-------------------------------------------------------------------------------------------------------------------------"
260 for(imem = 0; imem < 7; imem++)
265 sprintf(label,
"AvailMem");
268 sprintf(label,
"Total Mem");
271 sprintf(label,
"Committed_AS");
274 sprintf(label,
"SwapTotal");
277 sprintf(label,
"SwapFree");
280 sprintf(label,
"AllocMem");
283 sprintf(label,
"avail /dev/shm");
286 printf(
"%s:\t Largest = %10.2f Mb (on task=%4d), Smallest = %10.2f Mb (on task=%4d), Average = %10.2f Mb\n", label,
287 maxsize[imem] / (1024.0), maxtask[imem], minsize[imem] / (1024.0), mintask[imem], avgsize[imem] / (1024.0 *
NTask));
290 "-------------------------------------------------------------------------------------------------------------------------"
294 char name[MPI_MAX_PROCESSOR_NAME];
299 MPI_Get_processor_name(name, &len);
302 MPI_Bcast(name, MPI_MAX_PROCESSOR_NAME, MPI_BYTE, maxtask[2],
Communicator);
306 printf(
"Task=%d has the maximum commited memory and is host: %s\n",
ThisTask, name);
308 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
322 if(!(x & 0xffff0000u))
327 if(!(x & 0xff000000u))
332 if(!(x & 0xf0000000u))
337 if(!(x & 0xc0000000u))
342 if(!(x & 0x80000000u))
long long SharedMemoryOnNode
long long report_free_size_in_tmpfs(void)
void mpi_report_comittable_memory(void)
long long report_comittable_memory(long long *MemTotal, long long *Committed_AS, long long *SwapTotal, long long *SwapFree)
void subdivide_evenly_get_bin(int N, int pieces, int index, int *bin)
void permutate_chunks_in_list(int ncount, int *list)
gsl_rng * random_generator
int my_fls(unsigned int x)
void subdivide_evenly(long long N, int pieces, int index_bin, long long *first, int *count)
void init_rng(int thistask)
void myflush(FILE *fstream)
double get_random_number(void)
void enable_core_dumps_and_fpu_exceptions(void)