Parallel output using MPI IO to a single file -
I have a very simple job, but somehow I'm still trapped.
I have a large data file ("File_initial.dat"), should be read by all the nodes on the cluster (using MPI) which will display some manipulation from this large file (FILE_SIZE / Number_of_node) and finally each node will write the result in a shared BIG file ("File_final.dat"). The number of elements of the files remains the same.
-
By Googling I understood that it is better to write the data file as a binary file (I only have decimal numbers in this file) and the format of * .txt file Not in Since no human can read this file, only computers.
-
I tried to apply myself (but formatted and output in the output binary file), but I get wrong behavior < / Ol>
My code is as follows:.
Include # lt; Fstream & gt; #define NNN 30 integer main (int argc, char ** argv) {wing ifstream; // MPI environment integer rank, installation of nprocs; MPI_File file; MPI_Init (& amp; argc, & argv); MPI_Comm_size (MPI_COMM_WORLD, & amp; nprocs); MPI_Comm_rank (MPI_COMM_WORLD, & amp; Rank); // read the initial fin.open file "(initial.txt"); For (int i = 0; i & lt; nnn; i ++) {wings & gt; & Gt; Race [i]; Cout & lt; Res [i] & lt; & Lt; Endl; // to view, what do I have in the file} fin.close (); // "status" process in the "res" array of RT PtA = (NNN / NPROX) * rank; // file MPI_Offset offset = sizeof (double) * Specify the offset to write for the rank; MPI_File file; MPI_Status status; // open a shared file MPI_File_open (MPI_COMM_WORLD, "final.txt", MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, & amp; file); // local settings for each node array * Local Aerere; LocalArray = New Double [NNN / NPROPs]; // For some basic manipulation (class of each element of the array) (int i = 0; i & lt; (nnn / nprocs); i ++) display {localArray [i] = race [pstart + i] * race [Pstart + i]; } // Writing the result of each local array in the shared final file: MPI_File_seek (file, offset, MPI_SEE_STT); MPI_File_write (file, localair, size (double), MPIDouble, and position); MPI_File_close (& amp; file); MPI_Finalize (); Return 0; }
I understand that I do something wrong, while trying to write double as a text file.
How should anyone be able
- .txt file (format output) as
- .at file (binary file) )
Your binary file output is almost correct; But the amount of data to calculate and write for your offset within the file is incorrect. You want your offset be
MPI offset offset = double (double) * pert;
not
MPI offset offset = size (double) * rank;
Otherwise you will be writing on each other's data on each rank (say)
nprocs = 5 outside the rank 3 file starts writing at double number 3 Is not, (30/5) * 3 = 18
In addition, you want that each rank
NNN / nprocs doubles, not
sizeof (double) couple, i.e. you want
MPI_File_write (file, localair, NNN / NPROX, MPIDouble, and status);
How to write as a text file is a big issue; You have to convert the data internally to the string and then output those strings, make sure that the description of how many letters are required for each formatting carefully, is done on this site.
Comments
Post a Comment