Read external file

From: Jesus <jesusms_at_astro.ucla.edu>
Date: Mon, 15 Aug 2016 14:37:26 -0700

Hello,
I am trying to modify Gadget2 to read an external file that contains a grid of velocities to simulate turbulence. In summary, I did the following:

-I defined an array (static double rgrid[grid_size][grid_size][grid_size], where int grid_size = 128, and the array is static double to avoid problems with memory ) in the file allvars.h
-I set up a function to read a file and store the values in the 3D array 'rgrid' in a file called "read_file.h". The function is called "read_turb()" and in it I have a printf statement that says "File read" when the process is completed.
-I include "read_file.h" in the file "main.c", and I wrote the function "read_file()" at the beginning of the main function.

Gadget2 compiles fine (it tells me that the rgrid is defined but not used, but whatever, it compiles), however when I run the program, the statement "File read" appears 8 times. I supposed is has something to do with the paralelization (I have 8 cores), so the file is being read 8 times and thus takes a long time. Is there a way to avoid this problem? i.e. to read the file just once. I wrote the function before the MPI_Init command in the main file so I assumed that the paralelization would not have started then, but I guess I was wrong.

Thank you for your help


-Jesus
Received on 2016-08-15 23:35:59

This archive was generated by hypermail 2.3.0 : 2023-01-10 10:01:32 CET