This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: segfault on memory intensive programs


--- Dave Korn <dave.korn@artimi.com> wrote:

> On 29 March 2006 21:22, Pete wrote:
> 
> > I have some benchmarkign code
> > 
> > #define  N          600 // Matrix rank
> > #define ITERATIONS 2000
> > 
> > 
> > 
> > int main( void )
> > {
> > 	// Set up the timer and start it ticking.
> > 	Timer timer;
> > 	timer.startTimer();
> > 
> > 	// We multiply m1 and m2, and put the result in
> m3.
> > 	int m1[N][N];
> > 	int m2[N][N];
> > 	int m3[N][N];
> > ...
> > 
> 
>   Your testcase didn't even compile for me! It
> complained about those three dots!

Hi Dave,

Thanks for replying.  Here's the rest of the code.  It
segfaults when N >= 417:




#define  N           600   // The dimension of the
matrices
#define  ITERATIONS 2000   // Number of times to
perform multiplication.

#include "Timer.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
static void complain_and_die( void );
static int  getInt( const int low, const int high );
static void fill_matrix( int m[][N] );
static void matrix_multiplication( const int a[][N],
const int b[][N], int result[][N] );



int main( void )
{
   // Set up the timer and start it ticking.
   Timer timer;
   timer.startTimer();

   // We multiply m1 and m2, and put the result in m3.
   int m1[N][N];
   int m2[N][N];
   int m3[N][N];

   // Seed the random number generator
   srand( time(NULL) );

   // Perform the multiplication ITERATIONS times.
   for ( int i = 0; i < ITERATIONS; ++i )
   {
      fill_matrix( m1 );
      fill_matrix( m2 );
      matrix_multiplication( m1, m2, m3 );
   }

   // Stop the timer and end the program.
   timer.endTimer();
   timer.printStats();
   return 0;
}



inline static void complain_and_die( void )
{
   fprintf( stderr, "I need the rank of the matrix\n"
);
   exit(1);
}



inline static int getInt( const int low, const int
high )
{
   return low + ( rand() % (high - low + 1) );
}



inline static void fill_matrix( int m[][N] )
{
   for ( int i = 0; i < N; ++i )
      for ( int j = 0; j < N; ++j )
         m[i][j] = getInt(0, 100);
}



inline static void matrix_multiplication( const int
a[][N], const int b[][N], int result[][N] )
{
   for( int i = 0; i < N; ++i )
      for( int j = 0; j < 3; ++j )
         for( int k = 0; k < N ; ++k )
            result[i][j] = a[i][k] + b[k][j];
}


The executable is produced with:

$ make
g++ -W -Wall -O9 -funroll-loops -mtune=pentium4   -c
-o matrix_mult_r.o matrix_mult_r.cc
g++ -W -Wall -O9 -funroll-loops -mtune=pentium4   -c
-o Timer.o Timer.cc
g++ -o matrix_mult_r.exe *.o

but it segfaults with and without the optimization
flags.

Pete

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]