Thanks every body for replay<br> yah I have implement C program to write integers to a (binary) file and also read a single value by each process. but the confusion for me is that how to read more than one integer values from file and store in array, because storing values in array we must allocate memory for the array of size file(values)/process. and I want read from a single file by multiple processes and store the values in arrays of each processes.<br>
Example of write to Binary file is.<br>#include <stdio.h><br>#include <mpi.h><br><br>void main(int argc, char *argv[])<br>{<br> int comm_size,comm_rank;<br> int size_int,amode;<br><br> MPI_Datatype etype,filetype;<br>
MPI_Info info;<br> MPI_Status status;<br> MPI_File fh;<br> MPI_Offset disp;<br><br> MPI_Init(&argc, &argv);<br> MPI_Comm_rank(MPI_COMM_WORLD,&comm_rank);<br> MPI_Comm_size(MPI_COMM_WORLD,&comm_size);<br>
<br> fname="data.dat";<br> drep="native";<br><br> amode=(MPI_MODE_CREATE|MPI_MODE_WRONLY);<br> size_int=sizeof(size_int);<br> info=MPI_INFO_NULL;<br><br> MPI_File_open(MPI_COMM_WORLD,"data.dat",amode,info,&fh);<br>
<br> disp=comm_rank*size_int;<br> etype=MPI_INTEGER;<br> filetype=MPI_INTEGER;<br><br> MPI_File_set_view(fh,disp,etype,filetype,"native",info);<br><br> MPI_File_write_at(fh,disp,&comm_rank,1,MPI_INTEGER,&status);<br>
<br> printf("Hello from rank %d. I wrote: %d\n",comm_rank,comm_rank);<br><br> MPI_File_close(&fh);<br> MPI_Finalize();<br>}<br><br>and Example to read values from the file<br><br>#include <stdio.h><br>
#include <mpi.h><br><br>void main(int argc, char *argv[])<br>{<br> int comm_size,comm_rank;<br> int size_int,amode,itest;<br><br> MPI_Datatype etype,filetype;<br> MPI_Info info;<br> MPI_Status status;<br> MPI_File fh;<br>
MPI_Offset disp;<br><br> MPI_Init(&argc, &argv);<br> MPI_Comm_rank(MPI_COMM_WORLD,&comm_rank);<br> MPI_Comm_size(MPI_COMM_WORLD,&comm_size);<br><br> amode=(MPI_MODE_RDONLY);<br> size_int=sizeof(size_int);<br>
info=MPI_INFO_NULL;<br><br> MPI_File_open(MPI_COMM_WORLD,"data.dat",amode,info,&fh);<br><br> disp=comm_rank*size_int;<br> etype=MPI_INTEGER;<br> filetype=MPI_INTEGER;<br><br><br> MPI_File_set_view(fh,disp,etype,filetype,"native",info);<br>
<br> MPI_File_read_at(fh,disp,&itest,1,MPI_INTEGER,&status);<br><br> printf("Hello from rank %d. I wrote: %d.n",comm_rank,itest);<br><br> MPI_File_close(&fh);<br> MPI_Finalize();<br>}<br><br><br>
<br>thanks for precious time. <br>