Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: complete workaround in the error msg seen on modern systems
[simgrid.git] / teshsuite / smpi / io-shared / io-shared.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <memory.h>
6
7 /* Test reading and writing zero bytes (set status correctly) */
8
9 int main( int argc, char *argv[] )
10 {
11     int errs = 0;
12     int size;
13     int rank;
14     int* buf;
15     int count;
16     MPI_File fh;
17     MPI_Comm comm;
18     MPI_Status status;
19  
20     MPI_Init( &argc, &argv );
21  
22     comm = MPI_COMM_WORLD;
23     MPI_File_open( comm, (char*)"/scratch/testfile", MPI_MODE_RDWR | MPI_MODE_CREATE | MPI_MODE_DELETE_ON_CLOSE, MPI_INFO_NULL, &fh );
24     MPI_Comm_size( comm, &size );
25     MPI_Comm_rank( comm, &rank );
26     buf = (int *)malloc( sizeof(int) );
27     buf[0] = rank;
28
29     MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );
30     MPI_Barrier(comm);
31     
32     memset( &status, 0xff, sizeof(MPI_Status) );
33     MPI_File_write_shared( fh, buf, 1, MPI_INT, &status );
34     MPI_Get_count( &status, MPI_INT, &count );
35     if (count != 1) {
36         errs++;
37         fprintf( stderr, "Count not one (%d) on write\n", count );fflush(stderr);
38     }
39
40     /* Write nothing (check status) */
41     memset( &status, 0xff, sizeof(MPI_Status) );
42     MPI_File_write_shared( fh, buf, 0, MPI_INT, &status );
43     MPI_Get_count( &status, MPI_INT, &count );
44     if (count != 0) {
45         errs++;
46         fprintf( stderr, "Count not zero (%d) on write\n", count );fflush(stderr);
47     }
48
49     MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );
50     MPI_Barrier(comm);
51     
52     memset( &status, 0xff, sizeof(MPI_Status) );
53     MPI_File_read_shared( fh, buf, 1, MPI_INT, &status );
54     MPI_Get_count( &status, MPI_INT, &count );
55     if (count != 1) {
56         errs++;
57         fprintf( stderr, "Count not zero (%d) on read shared\n", count );fflush(stderr);
58     }
59
60     free( buf );
61     MPI_File_close( &fh );
62  
63     MPI_Finalize();
64     return errs;
65 }