<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:'bookman old style', 'new york', times, serif;font-size:10pt;color:#000000;"><div></div><div><span class="Apple-style-span" style="font-family: verdana, arial, helvetica; font-size: 12px; "><p>Hello, <br></p><p>I have a MPI/C++ code for parallel reading from a single data file. There seems <br>to be some problem which I am not able to figure out. Pls point out my mistake. <br>Here is the code, data file and input: <br></p><p>// example of parallel MPI read from single file, in C++ <br>#include <iostream.h> <br>#include <mpi.h> <br></p><p>int main(int argc, char *argv[]) <br>{ <br> int bufsize, buf[15], count,rank,nprocs,i; <br> MPI_File fh; <br> MPI_Status
status; <br></p><p> MPI_Init(&argc, &argv); <br> MPI_Comm_rank(MPI_COMM_WORLD, &rank); <br> MPI_Comm_size(MPI_COMM_WORLD, &nprocs); <br></p><p> bufsize = sizeof(int)*30 / nprocs ; // local number to read <br> nints = bufsize/sizeof (int); <br></p><p> MPI_File_open <br>(MPI_COMM_WORLD,"testfile.dat",MPI_MODE_RDONLY,MPI_INFO_NULL,&fh); <br> MPI_File_seek(fh,rank*bufsize,MPI_SEEK_SET); <br> MPI_File_read(fh,&buf,nints,MPI_INT,&status); <br> MPI_File_close(&fh); <br></p><p> if(rank == 0) for(i=0;i<15;i++) cout<<"rank = "<<rank<<" "<<" i <br>= "<<i<<"
"<<buf[i]<<endl; <br> free (buf); <br> MPI_Finalize(); <br> return 0; <br>} </p><p><br></p></span> <span class="Apple-style-span" style="font-family: verdana, arial, helvetica; font-size: 12px; ">DATA FILE: </span></div><span class="Apple-style-span" style="font-family: verdana, arial, helvetica; font-size: 12px; "><p>1 <br>2 <br>3 <br>4 <br>5 <br>6 <br>7 <br>8 <br>9 <br>10 <br>11 <br>12 <br>13 <br>14 <br>15 <br>16 <br>17 <br>18 <br>19 <br>20 <br>21 <br>22 <br>23 <br>24 <br>25 <br>26 <br>27 <br>28 <br>29 <br>30 <br></p><p>OUTPUT: <br></p><p>mpirun -np 1 MPIfilehandling testfile.dat <br>rank = 0 i = 0 822751754 <br>rank = 0 i = 1 856306698 <br>rank = 0 i = 2
889861642 <br>rank = 0 i = 3 923416586 <br>rank = 0 i = 4 956969264 <br>rank = 0 i = 5 170995978 <br>rank = 0 i = 6 825362993 <br>rank = 0 i = 7 856305972 <br>rank = 0 i = 8 170997002 <br>rank = 0 i = 9 825625137 <br>rank = 0 i = 10 923414840 <br>rank = 0 i = 11 170998026 <br>rank = 0 i = 12 842009138 <br>rank = 0 i = 13 822751794 <br>rank = 0 i = 14 171062026 </p><p><br></p><p><span class="Apple-style-span" style="font-family: verdana, helvetica, sans-serif; font-size: x-small; "><span class="Apple-style-span" style="font-family: verdana, arial, helvetica; font-size: 12px; ">The mistake is not in your application per se. MPI I/O is not </span></span></p></span><span class="Apple-style-span" style="font-family: verdana, arial, helvetica; font-size: 12px; ">intended to read in general text files - it is intended for reading <br>files written by the MPI I/O interface. It definitely
doesn't do the <br>string to integer conversion necessary to read in your input file. </span><div><font class="Apple-style-span" face="verdana, arial, helvetica" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><span class="Apple-style-span" style="font-family: verdana, arial, helvetica; font-size: 12px; ">So if i want to parallelly read a single data file which hasn't written by the MPI I/O, what can i do?</span><div><font face="verdana, helvetica, sans-serif"><br><font color="#00407f" face="bookman old style, new york, times, serif" size="1">--------------------------------------------------------<br>Burak ISIKLI</font></font></div><div><font face="verdana, helvetica, sans-serif"><font color="#00407f" face="bookman old style, new york, times, serif" size="1">Dumlupinar University</font></font></div><div><font face="verdana, helvetica, sans-serif"><font color="#00407f" face="bookman old style, new
york, times, serif" size="1">Electrical & Electronics - Computer Engineering</font></font></div><div><font face="verdana, helvetica, sans-serif"><font color="#00407f" face="bookman old style, new york, times, serif" size="1"></font> </font></div><div><font face="verdana, helvetica, sans-serif"><font color="#00407f" face="bookman old style, new york, times, serif" size="1"><a rel="nofollow" target="_blank" href="http://burakisikli.wordpress.com">http://burakisikli.wordpress.com</a><br>--------------------------------------------------------</font></font></div><div><br></div><div style="position:fixed"></div>
<!-- cg18.c2.mail.ac4.yahoo.com compressed/chunked Sun Dec 27 06:09:29 PST 2009 -->
</div></div><br>
</body></html>