Hello all,
So I have a program for which is is necessary for me to have many (7) large arrays (order of 8000x8000) of the type long double. Obviously, this has proven difficult for a novice programmer such as myself. My pointers are global... I suppose it does not have to be this way but it made the development of the program significantly easier and I use this function to allocate the desired memory.
Code:
void init(){
int i =0;
r = malloc(sizeof(long double)*NUM_PARTICLES); rx = malloc(sizeof(long double)*NUM_PARTICLES);
ry = malloc(sizeof(long double)*NUM_PARTICLES); rz = malloc(sizeof(long double)*NUM_PARTICLES);
x = malloc(sizeof(long double)*NUM_PARTICLES);
y = malloc(sizeof(long double)*NUM_PARTICLES); z = malloc(sizeof(long double)*NUM_PARTICLES);
for(i=0;i<NUM_PARTICLES;++i) {
r[i] = malloc(sizeof(long double)*NUM_PARTICLES); rx[i] = malloc(sizeof(long double)*NUM_PARTICLES);
ry[i] = malloc(sizeof(long double)*NUM_PARTICLES); rz[i] = malloc(sizeof(long double)*NUM_PARTICLES);
}
rAA = malloc(sizeof(long double)*NUM_A); rAB = malloc(sizeof(long double)*NUM_A);
rBB = malloc(sizeof(long double)*NUM_B);
for(i=0;i<NUM_A;++i) {
rAA[i] = malloc(sizeof(long double)*NUM_A);
}
for(i=0;i<NUM_B;++i) {
rAB[i] = malloc(sizeof(long double)*NUM_B);
rBB[i] = malloc(sizeof(long double)*NUM_B);
}
}
The memory is freed with
Code:
void delete(){
int i =0;
for(i=0;i<NUM_PARTICLES;++i) {
free(r[i]); free(rx[i]);
free(ry[i]); free(rz[i]);
}
free(r); free(rx); free(ry); free(rz);
free(x); free(y); free(z);
for(i=0;i<NUM_A;++i) {
free(rAA[i]);
}
for(i=0;i<NUM_B;++i) {
free(rAB[i]);
free(rBB[i]);
}
free(rAA); free(rAB); free(rBB);
}
Ideally I would then run through the rest of my program which does some calculations on particle positions as generated by a computer simulation and outputs the results to files. That all works fine as I tested it on very small systems. When I attempt to implement the large system, however, I was forced to switch to malloc to allocate for large data sets and I have become confused. I am receiving the following errors after my program runs for a few seconds and I must suspend my program from there.
Code:
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
a.out(3088) malloc: *** mmap(size=143360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
I have no clue what's going on. Any help would be hugely appreciated.
Cheers,
Paddon