Find the answer to your Linux question:
Results 1 to 4 of 4
Size of array in case of multiple declaration of array of higher size in C -------------------------------------------------------------------------------- As per your suggestion the following program work #include <stdio.h> float x[9500][9500]; int main(void) ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Location
    Meerut, Up, India
    Posts
    6

    Error message killed in yje compilation of C Program

    Size of array in case of multiple declaration of array of higher size in C

    --------------------------------------------------------------------------------

    As per your suggestion the following program work

    #include <stdio.h>
    float x[9500][9500];

    int main(void)
    {

    printf("fred\n");

    x[9499][9499]=3.0/5.0;

    printf("%f\n",x[9499][9499]);

    return 0;

    }

    But when we declare more than one two-dimensional array then the error" KILLED" is flashed in the following prgram. Please try to help so that i could declare more than one two dimensional array of float type as it is required in our research program.

    #include <stdio.h>
    float x[9500][9500];
    float y[9500][9500];
    int main(void)
    {

    printf("fred\n");

    x[9499][9499]=3.0/5.0;

    printf("%f\n",x[9499][9499]);

    y[9499][9499]=3.0/5.0;

    printf("%f\n",y[9499][9499]);

    return 0;

    }

    output message-"killed"

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    You previously raised this question here. The only new information you give us now is "yje". Maybe that's the clue. I googled yje, but didn't find anything useful.

    What can you tell us about yje?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Linux User nalg0rath's Avatar
    Join Date
    Sep 2004
    Location
    Stockholm
    Posts
    303
    Seems to work for me. Output:

    Code:
    fred
    0.600000
    0.600000
    The problem might not be with the program but with the system you are trying to run it on. I'm not sure what the problem might be.

    My guess is that when creating that big array the program allocates memory from the stack. There is probably a limit on your system somewhere that limits the amount of memory that can be allocated.

    Edit:
    You could test:
    Code:
    $ ulimit -a
    $ ulimit -s 1024
    The first command will display the current limit and the second is used to set the limit. I don't know how much memory you'll need. I'm currently at my school so I can't test it. On the computer I successfully ran the program on the limits are:
    Code:
    time(seconds)        unlimited
    file(blocks)         unlimited
    data(kbytes)         unlimited
    stack(kbytes)        8192
    coredump(blocks)     0
    nofiles(descriptors) 256
    vmemory(kbytes)      unlimited
    > wje_lf: haha! Have you ever noticed that the "t" and "h" keys are very close to "y" and "j" ? It took me a while to figure that one out.

  4. #4
    drl
    drl is online now
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    I agree with nalg0rath. If we are correct, then using ulimit, and perhaps a few experiments might reveal the maximum sizes of data arrays you can use. A parameterized version of your source file:
    Code:
    #include <stdio.h>
    
    #define SIZE 40000
    #define SM (SIZE-1)
    float x[ SIZE ][ SIZE ];
    float y[ SIZE ][ SIZE ];
    
    int main( void )
    {
    
      int mysize = SM;
      printf( "fred running with size %d \n", mysize );
    
      x[ mysize ][ mysize ] = 3.0 / 5.0;
    
      printf( "%f\n", x[ mysize ][ mysize ] );
    
      y[ mysize ][ mysize ] = 3.0 / 5.0;
    
      printf( "%f\n", y[ mysize ][ mysize ] );
    
      return 0;
    
    }
    On my system, one error message that I get from gcc for the SIZE 40000 on a box that has 1 GB of memory, gcc (GCC) 3.3.5 (Debian 1:3.3.5- is:
    Code:
    c1.c:5: error: size of array `x' is too large
    For size 20000, I was able to compile without error, but for execution I got:
    Code:
    % ./c1
    Killed
    Note that this was during execution, not compilation as your thread title is written.

    You can change the definition of SIZE to see what might fit in the computer in question.

    For many questions like this, it is helpful to include something about your environment -- which OS and compiler you are using, the memory and CPU on your computer, etc. ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...