Logo AND Algorithmique Numérique Distribuée

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