E3SM-Project / scorpio

A high-level Parallel I/O Library for structured grid applications
Other
21 stars 16 forks source link

ADIOS type only writes the first element of an array of attribute values #546

Closed dqwu closed 10 months ago

dqwu commented 11 months ago

It appears that there has been a longstanding problem with the ADIOS type, where it only writes the first element of an array of attribute values. This issue has not been identified by the current Fortran unit tests, as it has been confirmed that read buffers are not reset in some of the tests.

[Steps to reproduce]

First, check out latest scorpio master branch.

git clone https://github.com/E3SM-Project/scorpio.git
cd scorpio

Next, replace the content of examples/c/example1.c with the test code shown below.

#include <stdio.h>
#include <mpi.h>
#include <pio.h>
#ifdef TIMING
#include <gptl.h>
#endif

#define NUM_NETCDF_FLAVORS 2
#define NUM_ATT_VALS 10

int main(int argc, char* argv[])
{
    int ntasks;
    int format[NUM_NETCDF_FLAVORS];
    int iosysid;
    char filename[PIO_MAX_NAME];
    int num_flavors = 0;
    int ncid;
    int varid;
    int put_att_vals_data[NUM_ATT_VALS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

#ifdef TIMING
    GPTLinitialize();
#endif

    MPI_Init(&argc, &argv);

    MPI_Comm_size(MPI_COMM_WORLD, &ntasks);

    PIOc_Init_Intracomm(MPI_COMM_WORLD, ntasks, 1, 0, PIO_REARR_BOX, &iosysid);

#ifdef _PNETCDF
    format[num_flavors++] = PIO_IOTYPE_PNETCDF;
#endif
#ifdef _ADIOS2
    format[num_flavors++] = PIO_IOTYPE_ADIOS;
#endif

    for (int fmt = 0; fmt < num_flavors; fmt++)
    {
        sprintf(filename, "test_put_att_vals_%d.nc", fmt);

        PIOc_createfile(iosysid, &ncid, &(format[fmt]), filename, PIO_CLOBBER);

        PIOc_def_var(ncid, "dummy_scalar_var", PIO_INT, 0, NULL, &varid);

        PIOc_put_att(ncid, varid, "dummy_att", PIO_INT, NUM_ATT_VALS, put_att_vals_data);

        PIOc_enddef(ncid);

        PIOc_closefile(ncid);
    }

    PIOc_finalize(iosysid);

    MPI_Finalize();

#ifdef TIMING
    GPTLfinalize();
#endif

    return 0;
}

Then, build scorpio and run example1

mkdir build
cd build

ADIOS2_DIR=/path/to/adios2/installation \
CC=mpicc CXX=mpicxx FC=mpifort cmake -Wno-dev \
-DWITH_ADIOS2=ON \
-DADIOS_BP2NC_TEST=ON \
-DWITH_NETCDF=OFF \
-DPnetCDF_PATH=/path/to/pnetcdf/installation \
-DPIO_USE_MALLOC=ON \
-DPIO_ENABLE_EXAMPLES=ON \
..

make

cd examples/c

mpiexec -n 4 ./example1

Finally, dump the two output files for comparison.

ncdump test_put_att_vals_0.nc 
netcdf test_put_att_vals_0 {
variables:
    int dummy_scalar_var ;
        dummy_scalar_var:dummy_att = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
data:

 dummy_scalar_var = 0 ;
}

ncdump test_put_att_vals_1.nc 
netcdf test_put_att_vals_1 {
variables:
    int dummy_scalar_var ;
        dummy_scalar_var:dummy_att = 1 ;
data:

 dummy_scalar_var = 0 ;
}