Parallel-NetCDF / PnetCDF

Source code repository of PnetCDF library and utilities
https://parallel-netcdf.github.io
Other
83 stars 23 forks source link

error reading MPI_BYTE type with ncmpi_get_vard_all #76

Closed jedwards4b closed 3 years ago

jedwards4b commented 3 years ago

The following code seems to indicate that the ncmpi_get_vard_all is broken with respect to datatype MPI_BYTE I've tried with mpt/2.22 and openmpi/4.0.5 It's a simple test and only requires 1 mpi task.

The input file required is here.

#include <stdio.h>
#include <mpi.h>
#include <pnetcdf.h>

int main(int argc, char **argv)
{
    int node;
    int ncid;
    int mpierr, ierr;
    int varid;
    int bl[1];
    MPI_Aint disp[1];
    MPI_Datatype subarray[1];
    MPI_Datatype filetype;
    char iobuf[936];

    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &node);
    if (node > 0){
    printf("Test intended for 1 task\n");
    MPI_Abort(MPI_COMM_WORLD, -1);
    }
    subarray[0] = MPI_BYTE;
    bl[0] = 936;
    disp[0] = 0;

    mpierr = MPI_Type_create_struct(1, bl, disp, subarray, &filetype);
    if(mpierr) printf("%d mpierr %d\n", __LINE__, mpierr);
    mpierr = MPI_Type_commit(&filetype);
    if(mpierr) printf("%d mpierr %d\n", __LINE__, mpierr);

    ierr = ncmpi_open(MPI_COMM_WORLD, "ne4np4-esmf.nc", NC_NOWRITE, MPI_INFO_NULL, &ncid);
    if(ierr) printf("%d ierr %d\n", __LINE__, ierr);

    ierr = ncmpi_inq_varid(ncid, "numElementConn", &varid);
    if(ierr) printf("%d ierr %d\n", __LINE__, ierr);

    ierr = ncmpi_get_vard_all(ncid, varid, filetype, iobuf, bl[0], MPI_BYTE);
    if(ierr) printf("%d ierr %d\n", __LINE__, ierr);

    ierr = ncmpi_close(ncid);
    if(ierr) printf("%d ierr %d\n", __LINE__, ierr);

    for(int i=0;i<bl[0]; i++){
    printf("%d: %d %d\n", node, i, (unsigned int) iobuf[i]);
    }

    MPI_Finalize();
}
wkliao commented 3 years ago

What version of PnetCDF is used to run the test program (and to create the input file if different)?

jedwards4b commented 3 years ago

pnetcdf/1.12.2 is used in the test. I suspect that the input file was created with serial netcdf, but I don't know for sure, it's netcdf classic format.

wkliao commented 3 years ago

In NetCDF realm, there are two kinds of data types: numeric and non-numeric. The only non-numeric data type is NC_CHAR. NC_BYTE is a numeric data type, which means signed 1-byte integer and its corresponding MPI data type is MPI_SIGNED_CHAR, rather than MPI_BYTE. If you replaced MPI_BYTE with MPI_SIGNED_CHAR, then the test program runs fine.

jedwards4b commented 3 years ago

Awesome - thank you!