diff --git a/src/drivers/ncmpio/ncmpio_getput.m4 b/src/drivers/ncmpio/ncmpio_getput.m4 index ea94c2afd..98b943f67 100644 --- a/src/drivers/ncmpio/ncmpio_getput.m4 +++ b/src/drivers/ncmpio/ncmpio_getput.m4 @@ -117,8 +117,8 @@ put_varm(NC *ncp, { void *xbuf=NULL; int mpireturn, err=NC_NOERR, status=NC_NOERR, buftype_is_contig; - int el_size, need_convert, need_swap, in_place_swap, need_swap_back_buf=0; - int coll_indep, xtype_is_contig=1; + int el_size, need_convert, need_swap, need_swap_back_buf=0; + int coll_indep, xtype_is_contig=1, can_swap_in_place; MPI_Offset nelems=0, bnelems=0, nbytes=0, offset=0; MPI_Datatype itype, xtype=MPI_BYTE, imaptype, filetype=MPI_BYTE; MPI_File fh; @@ -168,13 +168,14 @@ put_varm(NC *ncp, need_convert = ncmpii_need_convert(ncp->format, varp->xtype, itype); need_swap = NEED_BYTE_SWAP(varp->xtype, itype); - in_place_swap = 0; + /* check if in-place byte swap can be enabled */ + can_swap_in_place = 1; if (need_swap) { - if (fIsSet(ncp->flags, NC_MODE_SWAP_ON)) - in_place_swap = 1; - else if (! fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) { /* auto mode */ + if (! fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) /* hint set by user */ + can_swap_in_place = 0; + else if (! fIsSet(ncp->flags, NC_MODE_SWAP_ON)) { /* auto mode */ if (nbytes > NC_BYTE_SWAP_BUFFER_SIZE) - in_place_swap = 1; + can_swap_in_place = 0; } } @@ -185,7 +186,7 @@ put_varm(NC *ncp, if (err != NC_NOERR) goto err_check; if (!need_convert && imaptype == MPI_DATATYPE_NULL && - (!need_swap || (in_place_swap && buftype_is_contig))) { + (!need_swap || (can_swap_in_place && buftype_is_contig))) { /* reuse buftype, bufcount, buf in later MPI file write */ xbuf = buf; if (need_swap) { diff --git a/src/drivers/ncmpio/ncmpio_i_getput.m4 b/src/drivers/ncmpio/ncmpio_i_getput.m4 index 09beb4add..2b0c4f02a 100644 --- a/src/drivers/ncmpio/ncmpio_i_getput.m4 +++ b/src/drivers/ncmpio/ncmpio_i_getput.m4 @@ -144,7 +144,7 @@ ncmpio_igetput_varm(NC *ncp, void *xbuf=NULL; int i, err=NC_NOERR, abuf_index=-1, isize, xsize, new_nreqs, rem; int mpireturn, buftype_is_contig=1, need_convert, free_xbuf=0; - int need_swap, in_place_swap, need_swap_back_buf=0; + int need_swap, can_swap_in_place, need_swap_back_buf=0; MPI_Offset nelems=0, nbytes, *ptr; MPI_Datatype itype, xtype, imaptype; NC_lead_req *lead_req; @@ -232,16 +232,15 @@ ncmpio_igetput_varm(NC *ncp, need_convert = ncmpii_need_convert(ncp->format, varp->xtype, itype); need_swap = NEED_BYTE_SWAP(varp->xtype, itype); - /* check if we can do byte swap in place */ - if (fIsSet(ncp->flags, NC_MODE_SWAP_ON)) - in_place_swap = 1; - else if (fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) - in_place_swap = 0; - else { /* mode is auto */ - if (nbytes <= NC_BYTE_SWAP_BUFFER_SIZE) - in_place_swap = 0; - else - in_place_swap = 1; + /* check if in-place byte swap can be enabled */ + can_swap_in_place = 1; + if (need_swap) { + if (! fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) /* hint set by user */ + can_swap_in_place = 0; + else if (! fIsSet(ncp->flags, NC_MODE_SWAP_ON)) { /* auto mode */ + if (nbytes > NC_BYTE_SWAP_BUFFER_SIZE) + can_swap_in_place = 0; + } } /* check whether this is a true varm call, if yes, imaptype will be a @@ -265,7 +264,7 @@ ncmpio_igetput_varm(NC *ncp, } else { if (!buftype_is_contig || imaptype != MPI_DATATYPE_NULL || - need_convert || (need_swap && in_place_swap == 0)) { + need_convert || (need_swap && can_swap_in_place == 0)) { /* cannot use buf for I/O, must allocate xbuf */ xbuf = NCI_Malloc((size_t)nbytes); free_xbuf = 1; diff --git a/src/drivers/ncmpio/ncmpio_i_varn.m4 b/src/drivers/ncmpio/ncmpio_i_varn.m4 index 55e0f3d32..073b39cad 100644 --- a/src/drivers/ncmpio/ncmpio_i_varn.m4 +++ b/src/drivers/ncmpio/ncmpio_i_varn.m4 @@ -169,13 +169,13 @@ igetput_varn(NC *ncp, if (fIsSet(reqMode, NC_REQ_WR)) { /* check if in-place byte swap can be enabled */ - int in_place_swap = 0; + int can_swap_in_place = 1; if (need_swap) { - if (fIsSet(ncp->flags, NC_MODE_SWAP_ON)) - in_place_swap = 1; - else if (! fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) { /* auto mode */ + if (! fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) /* hint set by user */ + can_swap_in_place = 0; + else if (! fIsSet(ncp->flags, NC_MODE_SWAP_ON)) { /* auto mode */ if (nbytes > NC_BYTE_SWAP_BUFFER_SIZE) - in_place_swap = 1; + can_swap_in_place = 0; } } @@ -195,7 +195,7 @@ igetput_varn(NC *ncp, err = ncmpio_abuf_malloc(ncp, nbytes, &xbuf, &abuf_index); if (err != NC_NOERR) goto fn_exit; } - else if (!need_convert && in_place_swap && isContig) { + else if (!need_convert && can_swap_in_place && isContig) { /* reuse buf and break it into multiple vara requests */ xbuf = buf; if (need_swap) need_swap_back_buf = 1; diff --git a/src/drivers/ncmpio/ncmpio_vard.c b/src/drivers/ncmpio/ncmpio_vard.c index 5de162106..e65d63df8 100644 --- a/src/drivers/ncmpio/ncmpio_vard.c +++ b/src/drivers/ncmpio/ncmpio_vard.c @@ -194,17 +194,19 @@ getput_vard(NC *ncp, need_swap = NEED_BYTE_SWAP(varp->xtype, etype); if (fIsSet(reqMode, NC_REQ_WR)) { - int in_place_swap = 0; + /* check if in-place byte swap can be enabled */ + int can_swap_in_place = 1; if (need_swap) { - if (fIsSet(ncp->flags, NC_MODE_SWAP_ON)) - in_place_swap = 1; - else if (! fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) { /* auto mode */ + if (! fIsSet(ncp->flags, NC_MODE_SWAP_OFF)) /* hint set by user */ + can_swap_in_place = 0; + else if (! fIsSet(ncp->flags, NC_MODE_SWAP_ON)) { /* auto mode */ if (filetype_size > NC_BYTE_SWAP_BUFFER_SIZE) - in_place_swap = 1; + can_swap_in_place = 0; } } + if (!need_convert && - (!need_swap || (in_place_swap && buftype_is_contig))) { + (!need_swap || (can_swap_in_place && buftype_is_contig))) { /* reuse buftype, bufcount, buf in later MPI file write */ xbuf = buf; if (need_swap) {