Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fecb25155d931002743d937112ab405d621da58d
[simgrid.git] / teshsuite / smpi / io-simple-at / io-simple-at.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( size * sizeof(int) );
27     buf[0] = rank;
28  
29     /* Write to file */
30     MPI_File_write_at( fh, sizeof(int)*rank, buf, 1, MPI_INT, &status );
31     MPI_Get_count( &status, MPI_INT, &count );
32     if (count != 1) {
33         errs++;
34         fprintf( stderr, "Wrong count (%d) on write_at\n", count );fflush(stderr);
35     }
36
37     /* Read nothing (check status) */
38     memset( &status, 0xff, sizeof(MPI_Status) );
39     MPI_File_read_at( fh, sizeof(int)*rank, buf, 0, MPI_INT, &status );
40     MPI_Get_count( &status, MPI_INT, &count );
41     if (count != 0) {
42         errs++;
43         fprintf( stderr, "Count not zero (%d) on read\n", count );fflush(stderr);
44     }
45
46     /* Write nothing (check status) */
47     memset( &status, 0xff, sizeof(MPI_Status) );
48     MPI_File_write_at( fh, sizeof(int)*rank, buf, 0, MPI_INT, &status );
49     if (count != 0) {
50         errs++;
51         fprintf( stderr, "Count not zero (%d) on write\n", count );fflush(stderr);
52     }
53
54     MPI_Barrier( comm );
55
56     for (int i = 0; i < size; i++)
57       buf[i] = -1;
58     MPI_File_read_at( fh, sizeof(int)*rank, buf, 1, MPI_INT, &status );
59     // if (buf[0] != rank) {
60         // errs++;
61         // fprintf( stderr, "%d: buf = %d\n", rank, buf[0] );fflush(stderr);
62     // }
63  
64     free( buf );
65     MPI_File_close( &fh );
66  
67     MPI_Finalize();
68     return errs;
69 }