|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2008 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <string.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
static char MTEST_Descrip[] = "Test file views with MPI_Type_create_resized";
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int i, nprocs, len, mpi_errno, buf[2], newbuf[4];
|
|
Packit Service |
c5cf8c |
int errs = 0;
|
|
Packit Service |
c5cf8c |
MPI_Offset size;
|
|
Packit Service |
c5cf8c |
MPI_Aint lb, extent;
|
|
Packit Service |
c5cf8c |
MPI_File fh;
|
|
Packit Service |
c5cf8c |
char *filename;
|
|
Packit Service |
c5cf8c |
MPI_Datatype newtype;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (nprocs != 1) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Run this program on 1 process\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
i = 1;
|
|
Packit Service |
c5cf8c |
while ((i < argc) && strcmp("-fname", *argv)) {
|
|
Packit Service |
c5cf8c |
i++;
|
|
Packit Service |
c5cf8c |
argv++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (i >= argc) {
|
|
Packit Service |
c5cf8c |
len = 8;
|
|
Packit Service |
c5cf8c |
filename = (char *) malloc(len + 10);
|
|
Packit Service |
c5cf8c |
strcpy(filename, "testfile");
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* fprintf(stderr, "\n*# Usage: resized -fname filename\n\n");
|
|
Packit Service |
c5cf8c |
* MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
argv++;
|
|
Packit Service |
c5cf8c |
len = (int) strlen(*argv);
|
|
Packit Service |
c5cf8c |
filename = (char *) malloc(len + 1);
|
|
Packit Service |
c5cf8c |
strcpy(filename, *argv);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_delete(filename, MPI_INFO_NULL);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* create a resized type comprising an integer with an lb at sizeof(int) and extent = 3*sizeof(int) */
|
|
Packit Service |
c5cf8c |
lb = sizeof(int);
|
|
Packit Service |
c5cf8c |
extent = 3 * sizeof(int);
|
|
Packit Service |
c5cf8c |
MPI_Type_create_resized(MPI_INT, lb, extent, &newtype);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&newtype);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* initialize the file */
|
|
Packit Service |
c5cf8c |
MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh;;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 4; i++)
|
|
Packit Service |
c5cf8c |
newbuf[i] = 55;
|
|
Packit Service |
c5cf8c |
MPI_File_write(fh, newbuf, 4, MPI_INT, MPI_STATUS_IGNORE);
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* write 2 ints into file view with resized type */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
buf[0] = 10;
|
|
Packit Service |
c5cf8c |
buf[1] = 20;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPI_File_set_view(fh, 0, MPI_INT, newtype, (char *) "native", MPI_INFO_NULL);
|
|
Packit Service |
c5cf8c |
if (mpi_errno != MPI_SUCCESS)
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_write(fh, buf, 2, MPI_INT, MPI_STATUS_IGNORE);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* read back file view with resized type and verify */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPI_File_set_view(fh, 0, MPI_INT, newtype, (char *) "native", MPI_INFO_NULL);
|
|
Packit Service |
c5cf8c |
if (mpi_errno != MPI_SUCCESS)
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 4; i++)
|
|
Packit Service |
c5cf8c |
newbuf[i] = 100;
|
|
Packit Service |
c5cf8c |
MPI_File_read(fh, newbuf, 2, MPI_INT, MPI_STATUS_IGNORE);
|
|
Packit Service |
c5cf8c |
if ((newbuf[0] != 10) || (newbuf[1] != 20) || (newbuf[2] != 100) || (newbuf[3] != 100)) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr,
|
|
Packit Service |
c5cf8c |
"newbuf[0] is %d, should be 10,\n newbuf[1] is %d, should be 20\n newbuf[2] is %d, should be 100,\n newbuf[3] is %d, should be 100,\n",
|
|
Packit Service |
c5cf8c |
newbuf[0], newbuf[1], newbuf[2], newbuf[3]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* read file back and verify */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_get_size(fh, &size);
|
|
Packit Service |
c5cf8c |
if (size != 4 * sizeof(int)) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "file size is %lld, should be %d\n", size, (int) (4 * sizeof(int)));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < 4; i++)
|
|
Packit Service |
c5cf8c |
newbuf[i] = 100;
|
|
Packit Service |
c5cf8c |
MPI_File_read(fh, newbuf, 4, MPI_INT, MPI_STATUS_IGNORE);
|
|
Packit Service |
c5cf8c |
if ((newbuf[0] != 10) || (newbuf[3] != 20) || (newbuf[1] != 55) || (newbuf[2] != 55)) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr,
|
|
Packit Service |
c5cf8c |
"newbuf[0] is %d, should be 10,\n newbuf[1] is %d, should be 55,\n newbuf[2] is %d, should be 55,\n newbuf[3] is %d, should be 20\n",
|
|
Packit Service |
c5cf8c |
newbuf[0], newbuf[1], newbuf[2], newbuf[3]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&newtype);
|
|
Packit Service |
c5cf8c |
free(filename);
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|