Subject: Re: Bus error - simple (?) C program
To: None <netbsd-help@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-help
Date: 09/10/2001 20:17:41
In article <Pine.NEB.4.33.0109101203200.3040-100000@S.Culver.Net>,
Mike Cheponis <mac@Wireless.Com> wrote:

Congratulations, you discovered a gcc bug.
matrix[9999][9999] is miscomputed by gcc.
try:

    i = 9999;
and
    matrix[i][i]);

in your printf.

mmm, over agressive constant folding.

christos


>I tried a variation of that program, making the array a global:
>
>/*
> *      Test program with a big matrix.
> */
>
>#include <stdio.h>
>#include <stdlib.h>
>
>#define N 10000
>float matrix[N][N];
>
>int main( void )
>{
>    int i;
>
>    printf( "Big Matrix\n\n" );
>    printf( "The matrix is %d by %d; it has %d elements.\n", N, N, N*N );
>    printf( "It uses %d bytes.\n", sizeof(matrix) );
>
>    for ( i = 0; i < N; i++ ) {
>      matrix[i][i] = (float)random();
>    }
>
>    printf( "\n" );
>    printf( "The last element of the matrix if %12.10f\n", matrix[N-1][N-1] );
>    printf( "\n" );
>
>    return 0;
>}
>
>
>And did this:
>
>$ ulimit -m 500000
>$ ulimit -d 999999
>$ ulimit -a
>cpu time (seconds)         unlimited
>file size (blocks)         unlimited
>data seg size (kbytes)     999999
>stack size (kbytes)        2048
>core file size (blocks)    unlimited
>resident set size (kbytes) 500000
>locked-in-memory size (kb) 168716
>processes                  80
>file descriptors           64
>
>S>dmesg|head
>
>NetBSD 1.5.2 (GENERIC) #0: Mon Aug 20 11:14:38 PDT 2001
>cpu0: AMD Athlon Model 4 (Thunderbird) (686-class), 1100.12 MHz
>total memory = 511 MB
>avail memory = 468 MB
>using 6574 buffers containing 26296 KB of memory
>
>
>$ cc matrix.c -o matrix
>$ time ./matrix
>Big Matrix
>
>The matrix is 10000 by 10000; it has 100000000 elements.
>It uses 400000000 bytes.
>
>zsh: bus error (core dumped)  ./matrix
>./matrix  0.00s user 3.18s system 22% cpu 14.350 total
>
>$ ll matrix.core
>1398752 -rw-------  1 mac  wheel  400,187,704 Sep 10 12:01 matrix.core
>
>
>
>
>So I'm confused, I have plenty of memory, I increased the limits, and it
>still craps out.
>
>Thanks -Mike
>