Logo AND Algorithmique Numérique Distribuée

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