Hi Jovana,
825307441 is 0x31313131 in base 16 (hexadecimal), which is the string
`1111' in ASCII. MPI_File_read reads in binary values (not ASCII) just
as the standard functions read(2) and fread(3) do.
So, your program is fine; however, your data file (first.dat) is not.
Cheers,
Shaun
Jovana Knezevic wrote:
Hello everyone!
I have a problems using MPI_File_read() in C. Simple code below,
trying to read an integer prints to the standard output wrong result
(instead of 1 prints 825307441). I tried this function with 'MPI_CHAR'
datatype and it works. Probably I'm not using it properly for MPI_INT,
but I can't find what can be a problem anywhere in the literature, so
I would really appreciate if anyone of you could check out the code
below quickly and maybe give me some advice, or tell me what's wrong
with it.
Thanks a lot in advance.
Regards,
Jovana Knezevic
#include <stdlib.h>
#include <stdio.h>
#include <mpi.h>
void
read_file (MPI_File *infile)
{
MPI_Status status;
int *buf;
int i;
buf = (int *)malloc( 5 * sizeof(int) );
for(i=0; i<5; i++)
buf[i]=0;
MPI_File_read(*infile, buf, 1, MPI_INT, &status);
printf("%d\n", buf[0]);
}
int
main (int argc, char **argv)
{
MPI_File infile1;
int procID, nproc;
MPI_Init (&argc, &argv);
MPI_Comm_rank (MPI_COMM_WORLD, &procID);
MPI_Comm_size (MPI_COMM_WORLD, &nproc);
printf("begin\n");
MPI_File_open(MPI_COMM_WORLD,"first.dat"
,MPI_MODE_RDONLY,MPI_INFO_NULL,&infile1);
if(procID==0) {
printf("proc0\n");
read_file(&infile1);
}
else
{
printf("proc1\n");
}
MPI_File_close(&infile1);
printf("end\n");
MPI_Finalize();
return EXIT_SUCCESS;
}
_______________________________________________
users mailing list
us...@open-mpi.org
http://www.open-mpi.org/mailman/listinfo.cgi/users