CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   3D DNS code in C with large arrays. (http://www.cfd-online.com/Forums/main/987-3d-dns-code-c-large-arrays.html)

S.Sri Govind July 5, 1999 07:25

3D DNS code in C with large arrays.
 
I've been trying to run this code that simulates turbulent spots for Couette flow.The code runs perfectly for a grid of 70*37*70, but gives a segmentation fault for a grid of 134*37*134. I've managed to track down the problem to a particular function, which is not able initialise the array (of the above size) fully.When I ask for the values to be printed before being sent to the function,the segmentation fault seems to occur when about 70 odd points are to be initialised.This occurs even when I Try to initialise only a part of the whole grid say 100*33*100.

Andrei Chernousov July 5, 1999 07:58

Re: 3D DNS code in C with large arrays.
 
You may use memory allocation function of the type:

#include <stdio.h> #include <process.h> #include <alloc.h>

/* Memory allocation procedure based on _nested_ pointers, w/o segmentation problems */

/************ * RECTMEM * For 2D (rectangular) array ************/ float **RectMem( int columns, int rows ) { float **x; int i;

if((x=(float**)farmalloc(columns*sizeof(float*)))= =NULL) {

printf("cannot allocate"); exit(0); } for( i = 0; i < columns; i++ )

if((x[i]=(float*)farmalloc(rows*sizeof(float)))==NULL) {

printf("cannot allocate"); exit(0);

} return x; } // end RectMem( )

// Good luck!

Andrei Chernousov July 6, 1999 03:00

Re: 3D DNS code in C with large arrays.
 
Excuse me, I posted message without preview

Memory allocation procedure based on _nested_ pointers, w/o segmentation problems (For 2D (rectangular) array):

include stdio.h

include stdlib.h

include alloc.h

float **RectMem( int columns, int rows )

{

float **x; int i;

if((x=(float**)farmalloc(columns*sizeof(float*)))= =NULL) { printf("cannot allocate"); exit(0); }

for( i = 0; i < columns; i++ )

if((x[i]=(float*)farmalloc(rows*sizeof(float)))==NULL) {

printf("cannot allocate"); exit(0);

}

return x;

} // end RectMem( )

clifford bradford July 23, 1999 13:09

Re: 3D DNS code in C with large arrays.
 
master i do not understand. could you explain what it is you're trying to do so that a plebian like myself can comprehend


All times are GMT -4. The time now is 09:35.