E3SM-Project / scorpio

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

Invalid var_desc_t type handle found in pio_buf_lim_tests #110

Open dqwu opened 6 years ago

dqwu commented 6 years ago

When PIO_TEST_CLOSE_OPEN_FOR_SYNC is ON, we first close a file and then reopen it.

After PIO_closefile is called, all existing var_desc_t type handles (obtained from previous PIO_def_var/PIO_inq_varid calls) become invalid and we should use PIO_inq_varid to renew them after reopening the file.

In pio_buf_lim_tests.F90.in, pio_var4 handle is not renewed, but it is still used to call PIO_write_darray.

PS, only ADIOS type can show the failure (for other types, the invalid handle for var4 happens to work)

...
    ierr = PIO_def_var(pio_file, PIO_VAR4_NAME, PIO_TF_DATA_TYPE, (/pio_dim/), pio_var4)
...
#ifdef PIO_TEST_CLOSE_OPEN_FOR_SYNC
    call PIO_closefile(pio_file)
    ierr = PIO_openfile(pio_tf_iosystem_, pio_file, iotypes(i), filename, PIO_write)
    ierr = PIO_inq_varid(pio_file, PIO_VAR1_NAME, pio_var1)
    ierr = PIO_inq_varid(pio_file, PIO_VAR2_NAME, pio_var2)
    ierr = PIO_inq_varid(pio_file, PIO_VAR3_NAME, pio_var3)
#else
    call PIO_syncfile(pio_file)
#endif
...
    ! ============ Flush every 3 vars ======================
...
    ! Flush for the previous 3 vars, pio_var1, pio_var2, pio_var3 should happen
    ! inside PIO_write_darray(pio_var4)
    call PIO_write_darray(pio_file, pio_var4, iodesc, wbuf, ierr)
    PIO_TF_CHECK_ERR(ierr, "Failed to write darray(var4) : " // trim(filename))
...
dqwu commented 6 years ago

Similar issue for pio_var3 in pio_buf_lim_tests.F90.in:

#ifdef PIO_TEST_CLOSE_OPEN_FOR_SYNC
...
    ierr = PIO_inq_varid(pio_file, PIO_VAR1_NAME, pio_var1)
    ierr = PIO_inq_varid(pio_file, PIO_VAR2_NAME, pio_var2)
#else
    call PIO_syncfile(pio_file)
#endif
...
    ! ============ Flush every 2 vars ======================
...
    ! Flush for the previous 2 vars, pio_var1 and pio_var2 should happen
    ! inside PIO_write_darray(pio_var3)
    call PIO_write_darray(pio_file, pio_var3, iodesc, wbuf, ierr)
jayeshkrishna commented 6 years ago

Looks like a bug (it works mostly because the underlying library just increments the id for vars). Can you go ahead and fix it (or do you want me to) - just add the missing inq_vars?