Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7fae204439d22ca141b33b6c0177716e55bff6a7
[simgrid.git] / teshsuite / smpi / io-ordered / io-ordered.c
1 #include "mpi.h"\r
2 #include <stdio.h>\r
3 #include <stdlib.h>\r
4 #include <string.h>\r
5 #include <memory.h>\r
6 \r
7 /* Test reading and writing zero bytes (set status correctly) */\r
8 \r
9 int main( int argc, char *argv[] )\r
10 {\r
11     int errs = 0;\r
12     int size, rank, i, *buf, count;\r
13     MPI_File fh;\r
14     MPI_Comm comm;\r
15     MPI_Status status;\r
16  \r
17     MPI_Init( &argc, &argv );\r
18  \r
19     comm = MPI_COMM_WORLD;\r
20     MPI_File_open( comm, (char*)"/scratch/lib/libsimgrid.so.3.6.2", MPI_MODE_RDWR | MPI_MODE_CREATE | MPI_MODE_DELETE_ON_CLOSE, MPI_INFO_NULL, &fh );\r
21     MPI_Comm_size( comm, &size );\r
22     MPI_Comm_rank( comm, &rank );\r
23     buf = (int *)malloc( 10* sizeof(int) );\r
24     buf[0] = rank;\r
25  \r
26     /* Write to file */\r
27     MPI_File_write_ordered( fh, buf, 10, MPI_INT, &status );\r
28     MPI_Get_count( &status, MPI_INT, &count );\r
29     if (count != 10) {\r
30         errs++;\r
31         fprintf( stderr, "Wrong count (%d) on write-ordered\n", count );fflush(stderr);\r
32     }\r
33     MPI_Barrier( comm );\r
34     MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );\r
35     for (i=0; i<size; i++) buf[i] = -1;\r
36     MPI_File_read_ordered( fh, buf, 10, MPI_INT, &status );\r
37 \r
38     MPI_Barrier(comm);\r
39     MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );\r
40 \r
41     free( buf );\r
42     MPI_File_close( &fh );\r
43  \r
44     MPI_Finalize();\r
45     return errs;\r
46 }