[mvapich-discuss] MPI Program using FILE I/O
shankha
shankhabanerjee at gmail.com
Wed Jun 30 10:06:15 EDT 2010
Hi,
I have a MPI program which uses ROMIO API's. The program runs and
executes fine without any issues.
The problem is I do not see the data which I wrote to the file. I
check for all possible error conditions. I am copying the program for
your reference.
The number of processes as of now is 8.
Command Line To Build the executable:
INSTAL_DIR=mpi install location.
mpicc -IINSTAL_DIR/include -IINSTAL_DIR/src/mpi/romio/include -g
-Wall -Wextra \
prog.c -o executable -LINSTAL_DIR/lib -lmpich
-Wl,-RINSTAL_DIR/lib -lpthread
Command line to execute the program :
mpiexec -np 8 ./executable
#include <stdio.h>
#include <mpi.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#define NUM_PROCESSES 8
#define BUF_SIZE 3
#define CHECK(a) \
{ \
if (!(a)) { \
fprintf(stderr, \
"(%d)Error at node %d, line %d of test program\n", \
myrank, myrank, __LINE__); \
} \
}
#define CHECKINTS(a, b) \
{ \
CHECK((int)(a) == (int)(b)); \
if ((int)(a) != (int)(b)) { \
fprintf(stderr, "(%d)got: %x expected: %x\n", \
myrank, (int)(a), (int)(b)); \
} \
}
#define CHECKERRS(a, b) \
{ \
char got_string[MPI_MAX_ERROR_STRING]; \
char expected_string[MPI_MAX_ERROR_STRING]; \
int string_len; \
int ca, cb; \
CHECK((int)(a) == (int)(b)); \
if ((int)(a) != (int)(b)) { \
MPI_Error_class(a, &ca); \
MPI_Error_class(b, &cb); \
CHECKINTS(ca, cb); \
if (ca != cb) { \
MPI_Error_string(a, got_string, &string_len); \
MPI_Error_string(b, expected_string, &string_len); \
fprintf(stderr, "(%d)got %d in class %d: %s\n", \
myrank, (int)(a), (int)ca, got_string); \
fprintf(stderr, "(%d)expected %d in class %d: %s\n", \
myrank, (int)(b), (int)cb, expected_string); \
} \
} \
}
int
main ( int argc, char **argv )
{
int myrank , size , i = 0, ret, amode;
int rank_arr [ NUM_PROCESSES / 2 ][ 2 ];
char filename [ 20 ];
int buf [ BUF_SIZE ];
bool odd_rank = false, even_rank = false;
MPI_File mpi_fp;
MPI_Group group_world, new_group [ NUM_PROCESSES / 2 ] ;
MPI_Comm new_comm [ NUM_PROCESSES / 2 ];
/* printf ( " %s \n ", argv [ 0 ] ); */
MPI_Init(&argc, &argv);
MPI_Comm_rank ( MPI_COMM_WORLD, &myrank );
MPI_Comm_size ( MPI_COMM_WORLD, &size );
assert ( size == NUM_PROCESSES );
amode = MPI_MODE_RDWR | MPI_MODE_CREATE;
if ( myrank == 0 )
printf ( "Num Procs : %d \n", size );
MPI_Barrier ( MPI_COMM_WORLD );
printf ( " My Rank = %d \n", myrank );
if ( ( myrank % 2 ) == 1 )
odd_rank = true;
else if ( ( myrank % 2 ) == 0 )
even_rank = true;
else
assert ( false );
i = 0;
while ( i < BUF_SIZE )
{
buf [i] = myrank;
i i++;
}
i = 0;
while ( i < NUM_PROCESSES )
{
rank_arr [i/2][ i % 2 ] = i;
i++;
}
ret = MPI_Comm_group ( MPI_COMM_WORLD, &group_world );
CHECKERRS ( ret , MPI_SUCCESS );
ret = MPI_Group_incl ( group_world, 2, rank_arr [ myrank/2 ] ,
&new_group [ myrank / 2 ] );
CHECKERRS ( ret , MPI_SUCCESS );
ret = MPI_Comm_create ( MPI_COMM_WORLD, new_group [ myrank / 2 ] ,
&new_comm [ myrank / 2 ] );
CHECKERRS ( ret , MPI_SUCCESS );
if ( new_comm [ myrank / 2] == MPI_COMM_NULL )
{
printf ( "Can't create
communicators %d \n" , __LINE__ );
exit ( EXIT_FAILURE );
}
memset ( filename, 0 , 20 );
strcpy ( filename, "test" );
sprintf ( filename + strlen ( "test" ), "%d", myrank / 2 );
ret = MPI_File_open ( new_comm [ myrank / 2 ], filename, amode,
MPI_INFO_NULL, &mpi_fp );
CHECKERRS ( ret , MPI_SUCCESS );
if ( mpi_fp == MPI_FILE_NULL )
{
printf ( " File cannot be opened \n");
exit ( EXIT_FAILURE );
}
MPI_Barrier ( new_comm [ myrank / 2] );
ret = MPI_File_set_view ( mpi_fp , ( myrank % 2 ) * sizeof ( int )
* BUF_SIZE , MPI_INT,
MPI_INT, "native", MPI_INFO_NULL );
CHECKERRS ( ret, MPI_SUCCESS );
MPI_Barrier ( new_comm [ myrank / 2] );
ret = MPI_File_write_all ( mpi_fp , buf, BUF_SIZE, MPI_INT,
MPI_STATUS_IGNORE );
CHECKERRS ( ret, MPI_SUCCESS );
MPI_Barrier ( new_comm [ myrank / 2] );
MPI_File_sync ( mpi_fp );
CHECKERRS ( ret, MPI_SUCCESS );
ret = MPI_File_close ( &mpi_fp );
CHECKERRS ( ret, MPI_SUCCESS );
ret = MPI_Comm_free ( &new_comm [ myrank / 2 ] );
CHECKERRS ( ret, MPI_SUCCESS );
ret = MPI_Group_free ( &new_group [ myrank / 2 ] );
CHECKERRS ( ret, MPI_SUCCESS );
ret = MPI_Group_free ( &group_world );
CHECKERRS ( ret, MPI_SUCCESS );
MPI_Finalize();
return 0;
}
Thanks for your help.
--
Thanks
Shankha
More information about the mvapich-discuss
mailing list