Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] Problem with MPI_File_read()
From: Jovana Knezevic (jovana.knezevic.83_at_[hidden])
Date: 2009-04-14 16:21:06

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.

Jovana Knezevic

#include <stdlib.h>
#include <stdio.h>
#include <mpi.h>

read_file (MPI_File *infile)
  MPI_Status status;
  int *buf;
  int i;
  buf = (int *)malloc( 5 * sizeof(int) );

  for(i=0; i<5; i++)

  MPI_File_read(*infile, buf, 1, MPI_INT, &status);
  printf("%d\n", buf[0]);

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);


 if(procID==0) {