LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   multiple arrays (https://www.linuxquestions.org/questions/programming-9/multiple-arrays-883766/)

nushki 05-31-2011 12:11 PM

multiple arrays
 
Hi all,

im stuck again with something simple. there is a 4-dimensional array, but it gives segmentation fault when one of dimensions is big like 30000. dont know why :"(



#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#define N_I 30000


int main (int argc, char* argv[])
{
printf("!!!!1 \n");
int m[18][30][N_I][4];
int i,j,k,l;
for (i=0;i<18;i++)
for (j=0;j<30;j++)
for (k=0;k<N_I;k++)
for (l=0;l<4;l++)
{
m[i][j][k][l]=i+j+k+l;
printf("%d\n",m[i][j][k][l]);
}

return 0;
}


it works fine when N_I=300; but crashes when N_I=30000;



thank you

nushki 05-31-2011 12:21 PM

ups, i think i got it, i run in on cluster and since big arrays take a lot of space may be it was not allowed to take it, but when i run it on my laptop it works.


sorry

Nathan.eth0 05-31-2011 12:27 PM

You cant use that many loops. Your program crashes. Depending on how much your RAM capacity is, there are limitations.
Once I was trying to create a word combination list, I used multiple for loops but my core got dumped.
Its way more complex than you could understand. :D

dwhitney67 05-31-2011 12:44 PM

Quote:

Originally Posted by nushki (Post 4372139)
ups, i think i got it, i run in on cluster and since big arrays take a lot of space may be it was not allowed to take it, but when i run it on my laptop it works.


sorry

If you wish, try increasing the size of your stack, using the following command:
Code:

ulimit -s unlimited
Then re-run your program.... but seriously, why would you want to? Do you really want the program looping so many times?

Next time, if you require a large array (single or multi-dimensional), allocate it on the heap rather than declare it on the stack.

nushki 05-31-2011 12:51 PM

thank you!!!


All times are GMT -5. The time now is 10:10 AM.