Skip to content

Commit 6ca0d27

Browse files
committed
Allow ADIOS files to be reopened in write mode in certain cases
Reopening files to append data is not supported by the ADIOS type. However, users might reopen an existing file in write mode without performing any actual write operations. In such cases, reopening an ADIOS file in write mode is acceptable. An error should only be returned when an actual append operation is attempted on a reopened ADIOS file.
1 parent f06a65a commit 6ca0d27

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

src/clib/pio_darray.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,27 @@ int PIOc_write_darray_impl(int ncid, int varid, int ioid, PIO_Offset arraylen, c
21692169
"Writing variable (%s, varid=%d) to file (%s, ncid=%d) failed. The file was not opened for writing, try reopening the file in write mode (use the PIO_WRITE flag)", pio_get_vname_from_file(file, varid), varid, pio_get_fname_from_file(file), file->pio_ncid);
21702170
}
21712171

2172+
if ((file->iotype == PIO_IOTYPE_ADIOS) || (file->iotype == PIO_IOTYPE_ADIOSC))
2173+
{
2174+
/* ADIOS type does not support open to append mode */
2175+
if (file->is_reopened)
2176+
{
2177+
GPTLstop("PIO:PIOc_write_darray");
2178+
GPTLstop("PIO:write_total");
2179+
GPTLstop("PIO:PIOc_write_darray_adios");
2180+
GPTLstop("PIO:write_total_adios");
2181+
spio_ltimer_stop(ios->io_fstats->wr_timer_name);
2182+
spio_ltimer_stop(ios->io_fstats->tot_timer_name);
2183+
spio_ltimer_stop(file->io_fstats->wr_timer_name);
2184+
spio_ltimer_stop(file->io_fstats->tot_timer_name);
2185+
return pio_err(ios, file, PIO_EADIOS2ERR, __FILE__, __LINE__,
2186+
"Writing variable (%s, varid=%d) to file (%s, ncid=%d) using ADIOS iotype failed. "
2187+
"Open to append mode is not supported yet",
2188+
pio_get_vname_from_file(file, varid), varid,
2189+
pio_get_fname_from_file(file), ncid);
2190+
}
2191+
}
2192+
21722193
/* Get decomposition information. */
21732194
if (!(iodesc = pio_get_iodesc_from_id(ioid)))
21742195
{

src/clib/pio_getput_int.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ int spio_put_att_tc(int ncid, int varid, const char *name, nc_type atttype,
6262

6363
if ((file->iotype == PIO_IOTYPE_ADIOS) || (file->iotype == PIO_IOTYPE_ADIOSC))
6464
{
65+
/* ADIOS type does not support open to append mode */
66+
if (file->is_reopened)
67+
{
68+
GPTLstop("PIO:spio_put_att_tc");
69+
GPTLstop("PIO:write_total");
70+
spio_ltimer_stop(ios->io_fstats->wr_timer_name);
71+
spio_ltimer_stop(ios->io_fstats->tot_timer_name);
72+
spio_ltimer_stop(file->io_fstats->wr_timer_name);
73+
spio_ltimer_stop(file->io_fstats->tot_timer_name);
74+
return pio_err(ios, file, PIO_EADIOS2ERR, __FILE__, __LINE__,
75+
"Writing variable (%s, varid=%d) attribute (%s) to file (%s, ncid=%d) using ADIOS iotype failed. "
76+
"Open to append mode is not supported yet",
77+
pio_get_vname_from_file(file, varid), varid, PIO_IS_NULL(name),
78+
pio_get_fname_from_file(file), ncid);
79+
}
80+
6581
GPTLstart("PIO:spio_put_att_tc_adios");
6682
GPTLstart("PIO:write_total_adios");
6783
}
@@ -2465,6 +2481,22 @@ int spio_put_vars_tc(int ncid, int varid, const PIO_Offset *start, const PIO_Off
24652481

24662482
if ((file->iotype == PIO_IOTYPE_ADIOS) || (file->iotype == PIO_IOTYPE_ADIOSC))
24672483
{
2484+
/* ADIOS type does not support open to append mode */
2485+
if (file->is_reopened)
2486+
{
2487+
GPTLstop("PIO:spio_put_vars_tc");
2488+
GPTLstop("PIO:write_total");
2489+
spio_ltimer_stop(ios->io_fstats->wr_timer_name);
2490+
spio_ltimer_stop(ios->io_fstats->tot_timer_name);
2491+
spio_ltimer_stop(file->io_fstats->wr_timer_name);
2492+
spio_ltimer_stop(file->io_fstats->tot_timer_name);
2493+
return pio_err(ios, file, PIO_EADIOS2ERR, __FILE__, __LINE__,
2494+
"Writing variable (%s, varid=%d) to file (%s, ncid=%d) using ADIOS iotype failed. "
2495+
"Open to append mode is not supported yet",
2496+
pio_get_vname_from_file(file, varid), varid,
2497+
pio_get_fname_from_file(file), ncid);
2498+
}
2499+
24682500
GPTLstart("PIO:spio_put_vars_tc_adios");
24692501
GPTLstart("PIO:write_total_adios");
24702502
}

src/clib/pioc_support.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4727,18 +4727,6 @@ int PIOc_openfile_retry_impl(int iosysid, int *ncidp, int *iotype, const char *f
47274727
#ifdef _ADIOS2
47284728
if ((file->iotype == PIO_IOTYPE_ADIOS) || (file->iotype == PIO_IOTYPE_ADIOSC))
47294729
{
4730-
if (mode & PIO_WRITE)
4731-
{
4732-
spio_ltimer_stop(ios->io_fstats->rd_timer_name);
4733-
spio_ltimer_stop(ios->io_fstats->tot_timer_name);
4734-
spio_ltimer_stop(file->io_fstats->rd_timer_name);
4735-
spio_ltimer_stop(file->io_fstats->tot_timer_name);
4736-
return pio_err(ios, NULL, PIO_EADIOS2ERR, __FILE__, __LINE__,
4737-
"Opening file (%s) using ADIOS iotype failed. "
4738-
"Open to append mode is not supported yet",
4739-
filename);
4740-
}
4741-
47424730
/* Trying to open a file with adios unless ADIOS_BP2NC_TEST option is enabled for unit tests */
47434731
bool adios2_file_exist = false;
47444732

0 commit comments

Comments
 (0)