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.
14 //#define NUM_X 536870911
15 #define NUM_X 53687091
18 //#define BIGDT 2147483643
19 #define BIGDT 214748364
21 int main(int argc, char **argv)
27 MPI_Datatype inner_type, rem_type, mem_type;
28 MPI_Datatype int_type, file_type;
29 int *buf_write, *buf_read;
35 MPI_Init(&argc, &argv);
37 if (sizeof(MPI_Aint) <= sizeof(int)) {
38 /* can't test on this platform... */
43 /* create a large buffer 2 */
44 buf_write = malloc(NUM_X * NUM_Y * sizeof(int));
45 if (buf_write == NULL) {
46 fprintf(stderr, "not enough memory\n");
49 buf_read = malloc(NUM_X * NUM_Y * sizeof(int));
50 if (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 if (MPI_File_open(MPI_COMM_WORLD, "testfile", MPI_MODE_RDWR | MPI_MODE_CREATE,
93 MPI_INFO_NULL, &fh) != 0) {
94 fprintf(stderr, "Can't open file: %s\n", "testfile");
98 if (MPI_SUCCESS != MPI_File_set_view(fh, 2144, MPI_BYTE, file_type, "native", MPI_INFO_NULL)) {
99 fprintf(stderr, "ERROR SET VIEW\n");
103 /* write everything */
104 rc = MPI_File_write_at_all(fh, 0, buf_write, 1, mem_type, MPI_STATUS_IGNORE);
105 if (rc != MPI_SUCCESS) {
106 fprintf(stderr, "%d ERROR WRITE AT ALL\n", rc);
110 if (MPI_SUCCESS != MPI_File_set_view(fh, 2144, MPI_BYTE, file_type, "native", MPI_INFO_NULL)) {
111 fprintf(stderr, "ERROR SET VIEW\n");
115 /* read everything */
116 rc = MPI_File_read_at_all(fh, 0, buf_read, 1, mem_type, MPI_STATUS_IGNORE);
117 if (rc != MPI_SUCCESS) {
118 fprintf(stderr, "%d ERROR READ AT ALL\n", rc);
122 /* for (k = 0; k < NUM_X * NUM_Y; k++) {
123 if (buf_read[k] != buf_write[k]) {
124 fprintf(stderr, "Verfiy Failed index %zu: expected %d found %d\n",
125 k, buf_write[k], buf_read[k]);
134 MPI_Type_free(&mem_type);
135 MPI_Type_free(&file_type);
139 printf(" No Errors\n");