Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
32 bits insists of having some timestamps off by 1us ... Hide them.
[simgrid.git] / teshsuite / smpi / io-all / io-all.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, rank, i, *buf, count;
13     MPI_File fh;
14     MPI_Comm comm;
15     MPI_Status status;
16  
17     MPI_Init( &argc, &argv );
18  
19     comm = MPI_COMM_WORLD;
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 );
21     MPI_Comm_size( comm, &size );
22     MPI_Comm_rank( comm, &rank );
23     buf = (int *)malloc( 10 * sizeof(int) );
24     buf[0] = rank;
25  
26     /* Write to file */
27     MPI_File_seek( fh, sizeof(int)*rank, MPI_SEEK_SET ); 
28     MPI_File_write_all( fh, buf, 1, MPI_INT, &status );
29     MPI_Get_count( &status, MPI_INT, &count );
30     if (count != 1) {
31         errs++;
32         fprintf( stderr, "Wrong count (%d) on write\n", count );fflush(stderr);
33     }
34     /* Write to file, overlapping */
35     MPI_File_seek( fh, sizeof(int)*rank, MPI_SEEK_SET ); 
36     MPI_File_write_all( fh, buf, 10, MPI_INT, &status );
37     MPI_Get_count( &status, MPI_INT, &count );
38     if (count != 10) {
39         errs++;
40         fprintf( stderr, "Wrong count (%d) on write\n", count );fflush(stderr);
41     }
42     /* Read nothing (check status) */
43     memset( &status, 0xff, sizeof(MPI_Status) );
44     MPI_File_read_all( fh, buf, 0, MPI_INT, &status );
45     MPI_Get_count( &status, MPI_INT, &count );
46     if (count != 0) {
47         errs++;
48         fprintf( stderr, "Count not zero (%d) on read\n", count );fflush(stderr);
49     }
50
51     /* Write nothing (check status) */
52     memset( &status, 0xff, sizeof(MPI_Status) );
53     MPI_File_write_all( fh, buf, 0, MPI_INT, &status );
54     if (count != 0) {
55         errs++;
56         fprintf( stderr, "Count not zero (%d) on write\n", count );fflush(stderr);
57     }
58
59     MPI_Barrier( comm );
60
61     MPI_File_seek( fh, sizeof(int)*rank, MPI_SEEK_SET );
62     for (i=0; i<size; i++) buf[i] = -1;
63     MPI_File_read_all( fh, buf, 10, MPI_INT, &status );
64     // if (buf[0] != rank) {
65         // errs++;
66         // fprintf( stderr, "%d: buf = %d\n", rank, buf[0] );fflush(stderr);
67     // }
68  
69     free( buf );
70     MPI_File_close( &fh );
71  
72     MPI_Finalize();
73     return errs;
74 }