Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add io test in mpich testsuite.
[simgrid.git] / teshsuite / smpi / mpich3-test / io / i_aggregation2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2014 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /* Look for regressions in aggregator code.  A more simple access pattern than
8  * aggregation1 */
9
10 /* Uses nonblocking collective I/O.*/
11
12 #include <mpi.h>
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <time.h>
17
18 #include <sys/types.h>
19 #include <unistd.h>
20
21 #include <string.h>
22
23 #define BUFSIZE 512
24
25 static void handle_error(int errcode, const char *str)
26 {
27     char msg[MPI_MAX_ERROR_STRING];
28     int resultlen;
29     MPI_Error_string(errcode, msg, &resultlen);
30     fprintf(stderr, "%s: %s\n", str, msg);
31     MPI_Abort(MPI_COMM_WORLD, 1);
32 }
33
34 int main(int argc, char **argv)
35 {
36     MPI_Info info = MPI_INFO_NULL;
37     MPI_File fh;
38     MPI_Offset off = 0;
39     MPI_Status status;
40     int errcode;
41     int i, rank, errs = 0, toterrs, buffer[BUFSIZE], buf2[BUFSIZE];
42     MPI_Request request;
43     const char *filename = NULL;
44
45     filename = (argc > 1) ? argv[1] : "testfile";
46
47     MPI_Init(&argc, &argv);
48
49     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
50
51     MPI_Info_create(&info);
52     MPI_Info_set(info, "romio_cb_write", "enable");
53     MPI_Info_set(info, "cb_nodes", "1");
54
55     for (i = 0; i < BUFSIZE; i++) {
56         buffer[i] = 10000 + rank;
57     }
58     off = rank * sizeof(buffer);
59
60     errcode = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_WRONLY | MPI_MODE_CREATE, info, &fh);
61     if (errcode != MPI_SUCCESS)
62         handle_error(errcode, "MPI_File_open");
63     errcode = MPI_File_iwrite_at_all(fh, off, buffer, BUFSIZE, MPI_INT, &request);
64     if (errcode != MPI_SUCCESS)
65         handle_error(errcode, "MPI_File_iwrite_at_all");
66     MPI_Wait(&request, &status);
67     errcode = MPI_File_close(&fh);
68     if (errcode != MPI_SUCCESS)
69         handle_error(errcode, "MPI_File_close");
70
71     errcode = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_RDONLY, info, &fh);
72     if (errcode != MPI_SUCCESS)
73         handle_error(errcode, "MPI_File_open");
74     errcode = MPI_File_iread_at_all(fh, off, buf2, BUFSIZE, MPI_INT, &request);
75     if (errcode != MPI_SUCCESS)
76         handle_error(errcode, "MPI_File_iread_at_all");
77     MPI_Wait(&request, &status);
78     errcode = MPI_File_close(&fh);
79     if (errcode != MPI_SUCCESS)
80         handle_error(errcode, "MPI_File_close");
81
82     for (i = 0; i < BUFSIZE; i++) {
83         if (buf2[i] != 10000 + rank)
84             errs++;
85     }
86     MPI_Allreduce(&errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
87     if (rank == 0) {
88         if (toterrs > 0) {
89             fprintf(stderr, "Found %d errors\n", toterrs);
90         }
91         else {
92             fprintf(stdout, " No Errors\n");
93         }
94     }
95     MPI_Info_free(&info);
96     MPI_Finalize();
97
98     return 0;
99 }