[mpich-discuss] Problems with MPI Romio code

shankha shankhabanerjee at gmail.com
Thu Jul 1 01:01:32 CDT 2010


Hi,
I am trying to open a File through the MPI_File_open and write to the
file using MPI_File_write.
Though all the calls seem to work fine when i try to open the file in
a editor I see junk.
I couldn't understand the reason why the file ( testfile ) to which I
am writing the array buf doesn't have the correct values.

MPI Version : mpicc for MPICH2 version 1.2.1p1, gcc version 4.4.3
(Ubuntu 4.4.3-4ubuntu5)

following is piece of code :
#include <stdio.h>
#include <mpi.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>

#define BUF_SIZE 3

int
main ( int argc , char **argv )
{
  int myrank , size , i = 0;
  MPI_File thefile;
  int buf [ BUF_SIZE ];
  MPI_Init(&argc, &argv);
  MPI_Comm_rank ( MPI_COMM_WORLD, &myrank );
  MPI_Comm_size ( MPI_COMM_WORLD, &size );

  for ( i = 0 ; i < BUF_SIZE ; i++ )
    buf [ i ] = 9;

  for ( i = 0 ; i < BUF_SIZE; i++ )
     buf [ i ] = myrank * BUF_SIZE + i;
  MPI_File_open ( MPI_COMM_WORLD, "testfile", MPI_MODE_CREATE |
MPI_MODE_WRONLY,
                    MPI_INFO_NULL, &thefile );
  MPI_File_set_view ( thefile, myrank * BUF_SIZE *  sizeof ( int ),
MPI_INT,
                      MPI_INT, "native", MPI_INFO_NULL );
  MPI_File_write ( thefile, buf, BUF_SIZE, MPI_INT,
MPI_STATUS_IGNORE );
  MPI_File_close ( &thefile );
  MPI_Finalize ();
  return 0;

}

Thanks for your help.
Thanks
Shankha


More information about the mpich-discuss mailing list