1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2014 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
13 //#define NUM_X 536870911
14 #define NUM_X 536870912
17 //#define BIGDT 2147483643
18 #define BIGDT 2147483647
21 static char MTEST_Descrip[] = "Nonblocking file read/write for bigtype";
24 int main(int argc, char **argv)
29 MPI_Datatype inner_type, rem_type, mem_type;
30 MPI_Datatype int_type, file_type;
31 int *buf_write, *buf_read;
39 MPI_Init(&argc, &argv);
41 if (sizeof(MPI_Aint) <= sizeof(int)) {
42 /* can't test on this platform... */
47 /* create a large buffer 2 */
48 buf_write = malloc(NUM_X * NUM_Y * sizeof(int));
49 buf_read = malloc(NUM_X * NUM_Y * sizeof(int));
50 if (buf_write == NULL || buf_read == NULL) {
51 fprintf(stderr, "Not enough memory\n");
54 memset(buf_read, 0, NUM_X * NUM_Y * sizeof(int));
56 for (i = 0; i < NUM_X; i++) {
57 for (j = 0; j < NUM_Y; j++) {
63 /* Big Datatype (2^31 - 1 bytes) */
64 MPI_Type_contiguous(BIGDT, MPI_BYTE, &inner_type);
65 /* Small Datatype (1 byte) */
66 MPI_Type_contiguous(1, MPI_BYTE, &rem_type);
75 /* combine both types */
76 MPI_Type_struct(2, block_len, disp, type, &mem_type);
78 MPI_Type_commit(&mem_type);
79 MPI_Type_free(&rem_type);
80 MPI_Type_free(&inner_type);
82 MPI_Type_contiguous(4, MPI_BYTE, &int_type);
84 /* This creates a big type that is actually contituous, touching an
85 * optimization that was at one point buggy */
86 MPI_Type_vector(1, NUM_X, 1, int_type, &file_type);
89 MPI_Type_commit(&file_type);
90 MPI_Type_free(&int_type);
92 rc = MPI_File_open(MPI_COMM_WORLD, "testfile",
93 MPI_MODE_RDWR | MPI_MODE_CREATE, MPI_INFO_NULL, &fh);
94 if (rc != MPI_SUCCESS) {
95 fprintf(stderr, "Can't open file: %s\n", "testfile");
99 rc = MPI_File_set_view(fh, 2144, MPI_BYTE, file_type, "native", MPI_INFO_NULL);
100 if (rc != MPI_SUCCESS) {
101 fprintf(stderr, "ERROR SET VIEW\n");
105 /* write everything */
106 rc = MPI_File_iwrite_at_all(fh, 0, buf_write, 1, mem_type, &request);
107 if (rc != MPI_SUCCESS) {
108 fprintf(stderr, "%d ERROR IWRITE AT ALL\n", rc);
111 MPI_Wait(&request, &status);
113 rc = MPI_File_set_view(fh, 2144, MPI_BYTE, file_type, "native", MPI_INFO_NULL);
114 if (rc != MPI_SUCCESS) {
115 fprintf(stderr, "ERROR SET VIEW\n");
119 /* read everything */
120 rc = MPI_File_iread_at_all(fh, 0, buf_read, 1, mem_type, &request);
121 if (rc != MPI_SUCCESS) {
122 fprintf(stderr, "%d ERROR IREAD AT ALL\n", rc);
125 MPI_Wait(&request, &status);
127 for (k = 0; k < NUM_X * NUM_Y; k++) {
128 if (buf_read[k] != buf_write[k]) {
129 fprintf(stderr, "Verfiy Failed index %zu: expected %d found %d\n",
130 k, buf_write[k], buf_read[k]);
139 MPI_Type_free(&mem_type);
140 MPI_Type_free(&file_type);
144 printf(" No Errors\n");