views:

591

answers:

3

Hi, all! Typing from Italy This little piece of code works if the matrix size is less then 800 and fails with a segmentation fault for higher sizes.... I have tried it with gcc 4.3.2 compiler in linux and macosx and VisualStudio compiler in windows. Seemsthe problem is in the stack size..... how can I increase it ? How can I solve the problem for bigger matrix sizes ? The code works fine in serial put fails in parallel execution. Thanks.

#include <omp.h>
#include <stdio.h>
#define Nu 4000
int main() {
float A[Nu][Nu],B[Nu][Nu],C[Nu][Nu];
int i,j;
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
#pragma omp parallel for private(j,i) shared(A,B,C) schedule(static)
for(j=0;j<Nu;j++){
for(i=0;i<Nu;i++){
//printf("Hello from thread %d, i,j %d %d\n", omp_get_thread_num(),i,j );
A[i][j]=0;
B[i][j]=0;
C[i][j]=0;

}}

}
+1  A: 

Default stack size in OpenMP is 4-8 MB. There's an environment variable called STACKSIZE you can change (for example to 16384, which is 16 MB). See chapter 5-5 of this PDF.

schnaader
+1  A: 

Do you really have to allocate the matrix on the stack?

You could use the heap instead. For large amounts of memory, it can even be more efficient (the allocator implementation can use things such as anonymous mmap which allow the memory to be released back to the operating system when you deallocate it).

CesarB
+1. @CesarB is right, objects of this size belong on the heap.
Mitch Wheat
A: 

you can adjust the stack size through the shell with

'ulimit -s newstacksize'

-- try 1000000

feydr