25 #ifndef MOAB_HAVE_NETCDF
26 #error "MBNcDispatch currently requires MOAB_HAVE_NETCDF. PNetCDF-only builds are not yet supported by this layer."
44 #ifdef MOAB_HAVE_PNETCDF
48 inline int to_mpi_offset_pair(
int libId,
int varid,
const size_t* start,
const size_t* count, MPI_Offset* outStart,
49 MPI_Offset* outCount,
int* outNdims )
52 int rc = ncmpi_inq_varndims( libId, varid, &ndims );
53 if( rc != NC_NOERR )
return rc;
54 if( ndims >
kMaxDims )
return NC_EMAXDIMS;
55 for(
int i = 0; i < ndims; ++i )
57 outStart[i] =
static_cast< MPI_Offset
>( start[i] );
58 outCount[i] =
static_cast< MPI_Offset
>( count[i] );
76 std::map< int, BufferedCtx >& buffered_registry()
78 static std::map< int, BufferedCtx > reg;
94 inline int bsuf_bcast_int(
int taggedId,
int rc_root,
int value_root,
int* out )
96 MPI_Comm comm = mbnc_buffered_comm( taggedId );
97 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
98 if( rc_root != NC_NOERR )
return rc_root;
99 MPI_Bcast( &value_root, 1, MPI_INT, 0, comm );
100 if( out ) *out = value_root;
105 inline int bsuf_bcast_size(
int taggedId,
int rc_root,
size_t value_root,
size_t* out )
107 MPI_Comm comm = mbnc_buffered_comm( taggedId );
108 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
109 if( rc_root != NC_NOERR )
return rc_root;
110 MPI_Bcast( &value_root,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, comm );
111 if( out ) *out = value_root;
117 inline int bsuf_bcast_bytes(
int taggedId,
int rc_root,
char*
buffer,
int nbytes )
119 MPI_Comm comm = mbnc_buffered_comm( taggedId );
120 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
121 if( rc_root != NC_NOERR )
return rc_root;
122 if(
buffer && nbytes > 0 ) MPI_Bcast(
buffer, nbytes, MPI_BYTE, 0, comm );
127 inline int bsuf_bcast_int_array(
int taggedId,
int rc_root,
int* buf,
int n )
129 MPI_Comm comm = mbnc_buffered_comm( taggedId );
130 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
131 if( rc_root != NC_NOERR )
return rc_root;
132 if( buf && n > 0 ) MPI_Bcast( buf, n, MPI_INT, 0, comm );
142 template <
typename T,
typename Fn >
143 int bsuf_get_vara(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count, T* data,
144 MPI_Datatype mpi_type, Fn nc_get_fn )
146 MPI_Comm comm = mbnc_buffered_comm( taggedFileId );
147 const int rank = mbnc_buffered_rank( taggedFileId );
148 const int size = mbnc_buffered_size( taggedFileId );
154 if( rank == 0 ) rc = nc_inq_varndims( libId, varid, &ndims );
155 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
156 if( rc != NC_NOERR )
return rc;
157 MPI_Bcast( &ndims, 1, MPI_INT, 0, comm );
158 if( ndims >
kMaxDims )
return NC_EMAXDIMS;
162 for(
int i = 0; i < ndims; ++i )
168 int my_rc = nc_get_fn( libId, varid, start, count, data );
172 for(
int src = 1; src < size; ++src )
175 MPI_Recv( srcStart, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 0, comm,
177 MPI_Recv( srcCount, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 1, comm,
180 for(
int i = 0; i < ndims; ++i )
182 std::vector< T > buf( n );
183 int s_rc = nc_get_fn( libId, varid, srcStart, srcCount, buf.data() );
184 MPI_Send( &s_rc, 1, MPI_INT, src, 2, comm );
185 if( s_rc == NC_NOERR && n > 0 ) MPI_Send( buf.data(),
static_cast< int >( n ), mpi_type, src, 3, comm );
192 MPI_Send( start, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 0, comm );
193 MPI_Send( count, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 1, comm );
195 MPI_Recv( &recv_rc, 1, MPI_INT, 0, 2, comm, MPI_STATUS_IGNORE );
196 if( recv_rc == NC_NOERR && my_n > 0 )
197 MPI_Recv( data,
static_cast< int >( my_n ), mpi_type, 0, 3, comm, MPI_STATUS_IGNORE );
211 std::FILE* fp = std::fopen( path,
"rb" );
214 unsigned char magic[8];
215 std::memset( magic, 0,
sizeof( magic ) );
216 const size_t nread = std::fread( magic, 1,
sizeof( magic ), fp );
222 if( magic[0] ==
'C' && magic[1] ==
'D' && magic[2] ==
'F' )
224 if( magic[3] == 0x01 || magic[3] == 0x02 || magic[3] == 0x05 )
return NCFMT_CLASSIC;
228 if( nread >= 8 && magic[0] == 0x89 && magic[1] ==
'H' && magic[2] ==
'D' && magic[3] ==
'F' && magic[4] == 0x0D &&
229 magic[5] == 0x0A && magic[6] == 0x1A && magic[7] == 0x0A )
250 #ifdef MOAB_HAVE_PNETCDF
252 #elif defined( MOAB_HAVE_NETCDFPAR )
262 #ifdef MOAB_HAVE_NETCDFPAR
283 void mbnc_register_buffered(
int taggedFileId, MPI_Comm comm )
287 MPI_Comm_rank( comm, &ctx.rank );
288 MPI_Comm_size( comm, &ctx.size );
289 buffered_registry()[taggedFileId] = ctx;
292 void mbnc_unregister_buffered(
int taggedFileId )
294 buffered_registry().erase( taggedFileId );
297 MPI_Comm mbnc_buffered_comm(
int taggedFileId )
299 auto it = buffered_registry().find( taggedFileId );
300 return ( it == buffered_registry().end() ) ? MPI_COMM_NULL : it->second.comm;
303 int mbnc_buffered_rank(
int taggedFileId )
305 auto it = buffered_registry().find( taggedFileId );
306 return ( it == buffered_registry().end() ) ? -1 : it->second.rank;
309 int mbnc_buffered_size(
int taggedFileId )
311 auto it = buffered_registry().find( taggedFileId );
312 return ( it == buffered_registry().end() ) ? 0 : it->second.size;
321 int mbnc_open_par(
NcBackend backend, MPI_Comm comm, MPI_Info info,
const char* path,
int omode,
int* taggedFileId )
328 #ifdef MOAB_HAVE_PNETCDF
330 rc = ncmpi_open( comm, path, omode, info, &libId );
333 #ifdef MOAB_HAVE_NETCDFPAR
335 rc = nc_open_par( path, omode | NC_MPIIO, comm, info, &libId );
341 MPI_Comm_rank( comm, &rank );
342 if( rank == 0 ) rc = nc_open( path, omode, &libId );
343 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
349 mbnc_register_buffered( *taggedFileId, comm );
355 rc = nc_open( path, omode, &libId );
365 int mbnc_create_par(
NcBackend backend, MPI_Comm comm, MPI_Info info,
const char* path,
int cmode,
int* taggedFileId )
372 #ifdef MOAB_HAVE_PNETCDF
374 rc = ncmpi_create( comm, path, cmode, info, &libId );
377 #ifdef MOAB_HAVE_NETCDFPAR
379 rc = nc_create_par( path, cmode | NC_MPIIO, comm, info, &libId );
384 MPI_Comm_rank( comm, &rank );
385 if( rank == 0 ) rc = nc_create( path, cmode, &libId );
386 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
390 mbnc_register_buffered( *taggedFileId, comm );
395 rc = nc_create( path, cmode, &libId );
406 int mbnc_open(
const char* path,
int omode,
int* taggedFileId )
409 int rc = nc_open( path, omode, &libId );
417 int rc = nc_create( path, cmode, &libId );
430 #ifdef MOAB_HAVE_PNETCDF
432 rc = ncmpi_close( libId );
435 #ifdef MOAB_HAVE_NETCDFPAR
437 rc = nc_close( libId );
441 rc = nc_close( libId );
446 const int rank = mbnc_buffered_rank( taggedFileId );
447 if( rank == 0 ) rc = nc_close( libId );
448 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
449 mbnc_unregister_buffered( taggedFileId );
468 #ifdef MOAB_HAVE_PNETCDF
469 if( backend ==
NCB_PNETCDF )
return ncmpi_redef( libId );
472 return nc_redef( libId );
479 #ifdef MOAB_HAVE_PNETCDF
480 if( backend ==
NCB_PNETCDF )
return ncmpi_enddef( libId );
483 return nc_enddef( libId );
486 int mbnc_def_dim(
int taggedFileId,
const char* name,
size_t len,
int* dimid )
490 #ifdef MOAB_HAVE_PNETCDF
491 if( backend ==
NCB_PNETCDF )
return ncmpi_def_dim( libId, name,
static_cast< MPI_Offset
>( len ), dimid );
494 return nc_def_dim( libId, name, len, dimid );
497 int mbnc_def_var(
int taggedFileId,
const char* name, nc_type xtype,
int ndims,
const int* dimids,
int* varid )
501 #ifdef MOAB_HAVE_PNETCDF
502 if( backend ==
NCB_PNETCDF )
return ncmpi_def_var( libId, name, xtype, ndims, dimids, varid );
505 return nc_def_var( libId, name, xtype, ndims, dimids, varid );
519 #ifdef MOAB_HAVE_PNETCDF
529 #ifdef MOAB_HAVE_PNETCDF
550 int rc = NC_NOERR, v = 0;
551 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_natts( libId, &v );
552 return bsuf_bcast_int( taggedFileId, rc, v, nattsp );
555 #ifdef MOAB_HAVE_PNETCDF
556 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_natts( libId, nattsp );
559 return nc_inq_natts( libId, nattsp );
569 int rc = NC_NOERR, v = 0;
570 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_ndims( libId, &v );
571 return bsuf_bcast_int( taggedFileId, rc, v, ndimsp );
574 #ifdef MOAB_HAVE_PNETCDF
575 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_ndims( libId, ndimsp );
578 return nc_inq_ndims( libId, ndimsp );
588 int rc = NC_NOERR, v = 0;
589 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_nvars( libId, &v );
590 return bsuf_bcast_int( taggedFileId, rc, v, nvarsp );
593 #ifdef MOAB_HAVE_PNETCDF
594 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_nvars( libId, nvarsp );
597 return nc_inq_nvars( libId, nvarsp );
607 int rc = NC_NOERR, v = 0;
608 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_dimid( libId, name, &v );
609 return bsuf_bcast_int( taggedFileId, rc, v, dimidp );
612 #ifdef MOAB_HAVE_PNETCDF
613 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_dimid( libId, name, dimidp );
616 return nc_inq_dimid( libId, name, dimidp );
619 int mbnc_inq_dim(
int taggedFileId,
int dimid,
char* name,
size_t* lenp )
628 char nameBuf[NC_MAX_NAME + 1] = { 0 };
631 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_dim( libId, dimid, nameBuf, &len );
633 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
634 if( rc != NC_NOERR )
return rc;
635 if( name ) MPI_Bcast( nameBuf, NC_MAX_NAME + 1, MPI_BYTE, 0, mbnc_buffered_comm( taggedFileId ) );
636 MPI_Bcast( &len,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, mbnc_buffered_comm( taggedFileId ) );
637 if( name ) std::memcpy( name, nameBuf, NC_MAX_NAME + 1 );
638 if( lenp ) *lenp = len;
642 #ifdef MOAB_HAVE_PNETCDF
646 int rc = ncmpi_inq_dim( libId, dimid, name, &tmp );
647 if( lenp ) *lenp =
static_cast< size_t >( tmp );
652 return nc_inq_dim( libId, dimid, name, lenp );
664 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_dimlen( libId, dimid, &v );
665 return bsuf_bcast_size( taggedFileId, rc, v, lenp );
668 #ifdef MOAB_HAVE_PNETCDF
672 int rc = ncmpi_inq_dimlen( libId, dimid, &tmp );
673 if( lenp ) *lenp =
static_cast< size_t >( tmp );
678 return nc_inq_dimlen( libId, dimid, lenp );
688 int rc = NC_NOERR, v = 0;
689 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_varid( libId, name, &v );
690 return bsuf_bcast_int( taggedFileId, rc, v, varidp );
693 #ifdef MOAB_HAVE_PNETCDF
694 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varid( libId, name, varidp );
697 return nc_inq_varid( libId, name, varidp );
707 char nameBuf[NC_MAX_NAME + 1] = { 0 };
709 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_varname( libId, varid, nameBuf );
710 int rc2 = bsuf_bcast_bytes( taggedFileId, rc, nameBuf, NC_MAX_NAME + 1 );
711 if( rc2 == NC_NOERR && name ) std::memcpy( name, nameBuf, NC_MAX_NAME + 1 );
715 #ifdef MOAB_HAVE_PNETCDF
716 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varname( libId, varid, name );
719 return nc_inq_varname( libId, varid, name );
730 int rc = NC_NOERR, v = 0;
731 if( mbnc_buffered_rank( taggedFileId ) == 0 )
734 rc = nc_inq_vartype( libId, varid, &t );
735 v =
static_cast< int >( t );
738 int rc2 = bsuf_bcast_int( taggedFileId, rc, v, &out );
739 if( rc2 == NC_NOERR && xtypep ) *xtypep =
static_cast< nc_type
>( out );
743 #ifdef MOAB_HAVE_PNETCDF
744 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_vartype( libId, varid, xtypep );
747 return nc_inq_vartype( libId, varid, xtypep );
757 int rc = NC_NOERR, v = 0;
758 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_varndims( libId, varid, &v );
759 return bsuf_bcast_int( taggedFileId, rc, v, ndimsp );
762 #ifdef MOAB_HAVE_PNETCDF
763 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varndims( libId, varid, ndimsp );
766 return nc_inq_varndims( libId, varid, ndimsp );
779 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_varndims( libId, varid, &ndims );
780 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
781 if( rc != NC_NOERR )
return rc;
782 MPI_Bcast( &ndims, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
783 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_vardimid( libId, varid, dimids );
784 return bsuf_bcast_int_array( taggedFileId, rc, dimids, ndims );
787 #ifdef MOAB_HAVE_PNETCDF
788 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_vardimid( libId, varid, dimids );
791 return nc_inq_vardimid( libId, varid, dimids );
801 int rc = NC_NOERR, v = 0;
802 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_varnatts( libId, varid, &v );
803 return bsuf_bcast_int( taggedFileId, rc, v, nattsp );
806 #ifdef MOAB_HAVE_PNETCDF
807 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varnatts( libId, varid, nattsp );
810 return nc_inq_varnatts( libId, varid, nattsp );
820 char nameBuf[NC_MAX_NAME + 1] = { 0 };
822 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_attname( libId, varid, attnum, nameBuf );
823 int rc2 = bsuf_bcast_bytes( taggedFileId, rc, nameBuf, NC_MAX_NAME + 1 );
824 if( rc2 == NC_NOERR && name ) std::memcpy( name, nameBuf, NC_MAX_NAME + 1 );
828 #ifdef MOAB_HAVE_PNETCDF
829 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_attname( libId, varid, attnum, name );
832 return nc_inq_attname( libId, varid, attnum, name );
835 int mbnc_inq_att(
int taggedFileId,
int varid,
const char* name, nc_type* xtypep,
size_t* lenp )
845 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc = nc_inq_att( libId, varid, name, &t, &len );
846 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
847 if( rc != NC_NOERR )
return rc;
848 int tInt =
static_cast< int >( t );
849 MPI_Bcast( &tInt, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
850 MPI_Bcast( &len,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, mbnc_buffered_comm( taggedFileId ) );
851 if( xtypep ) *xtypep =
static_cast< nc_type
>( tInt );
852 if( lenp ) *lenp = len;
856 #ifdef MOAB_HAVE_PNETCDF
860 int rc = ncmpi_inq_att( libId, varid, name, xtypep, &tmp );
861 if( lenp ) *lenp =
static_cast< size_t >( tmp );
866 return nc_inq_att( libId, varid, name, xtypep, lenp );
881 template <
typename T,
typename Fn >
882 int bsuf_get_att(
int taggedFileId,
int varid,
const char* name, T* value, MPI_Datatype mpi_type, Fn nc_get_att_fn )
884 MPI_Comm comm = mbnc_buffered_comm( taggedFileId );
885 const int rank = mbnc_buffered_rank( taggedFileId );
891 rc = nc_inq_attlen( libId, varid, name, &len );
892 if( rc == NC_NOERR ) rc = nc_get_att_fn( libId, varid, name, value );
894 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
895 if( rc != NC_NOERR )
return rc;
896 MPI_Bcast( &len,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, comm );
897 if( value && len > 0 ) MPI_Bcast( value,
static_cast< int >( len ), mpi_type, 0, comm );
908 if( backend ==
NCB_BUFFERED )
return bsuf_get_att< char >( taggedFileId, varid, name, value, MPI_CHAR, nc_get_att_text );
910 #ifdef MOAB_HAVE_PNETCDF
911 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_text( libId, varid, name, value );
914 return nc_get_att_text( libId, varid, name, value );
922 if( backend ==
NCB_BUFFERED )
return bsuf_get_att< int >( taggedFileId, varid, name, value, MPI_INT, nc_get_att_int );
924 #ifdef MOAB_HAVE_PNETCDF
925 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_int( libId, varid, name, value );
928 return nc_get_att_int( libId, varid, name, value );
937 return bsuf_get_att< short >( taggedFileId, varid, name, value, MPI_SHORT, nc_get_att_short );
939 #ifdef MOAB_HAVE_PNETCDF
940 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_short( libId, varid, name, value );
943 return nc_get_att_short( libId, varid, name, value );
952 return bsuf_get_att< long >( taggedFileId, varid, name, value, MPI_LONG, nc_get_att_long );
954 #ifdef MOAB_HAVE_PNETCDF
955 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_long( libId, varid, name, value );
958 return nc_get_att_long( libId, varid, name, value );
967 return bsuf_get_att< float >( taggedFileId, varid, name, value, MPI_FLOAT, nc_get_att_float );
969 #ifdef MOAB_HAVE_PNETCDF
970 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_float( libId, varid, name, value );
973 return nc_get_att_float( libId, varid, name, value );
982 return bsuf_get_att< double >( taggedFileId, varid, name, value, MPI_DOUBLE, nc_get_att_double );
984 #ifdef MOAB_HAVE_PNETCDF
985 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_double( libId, varid, name, value );
988 return nc_get_att_double( libId, varid, name, value );
995 int mbnc_put_att_text(
int taggedFileId,
int varid,
const char* name,
size_t len,
const char* value )
999 #ifdef MOAB_HAVE_PNETCDF
1001 return ncmpi_put_att_text( libId, varid, name,
static_cast< MPI_Offset
>( len ), value );
1004 return nc_put_att_text( libId, varid, name, len, value );
1007 int mbnc_put_att_int(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const int* value )
1011 #ifdef MOAB_HAVE_PNETCDF
1013 return ncmpi_put_att_int( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1016 return nc_put_att_int( libId, varid, name, xtype, len, value );
1019 int mbnc_put_att_short(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const short* value )
1023 #ifdef MOAB_HAVE_PNETCDF
1025 return ncmpi_put_att_short( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1028 return nc_put_att_short( libId, varid, name, xtype, len, value );
1031 int mbnc_put_att_float(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const float* value )
1035 #ifdef MOAB_HAVE_PNETCDF
1037 return ncmpi_put_att_float( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1040 return nc_put_att_float( libId, varid, name, xtype, len, value );
1043 int mbnc_put_att_double(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const double* value )
1047 #ifdef MOAB_HAVE_PNETCDF
1049 return ncmpi_put_att_double( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1052 return nc_put_att_double( libId, varid, name, xtype, len, value );
1063 #ifdef MOAB_HAVE_MPI
1065 return bsuf_get_vara< double >( taggedFileId, varid, start, count, data, MPI_DOUBLE, nc_get_vara_double );
1067 #ifdef MOAB_HAVE_PNETCDF
1072 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1073 if( rc != NC_NOERR )
return rc;
1074 return ncmpi_get_vara_double_all( libId, varid, s, c, data );
1078 return nc_get_vara_double( libId, varid, start, count, data );
1081 int mbnc_get_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
int* data )
1085 #ifdef MOAB_HAVE_MPI
1087 return bsuf_get_vara< int >( taggedFileId, varid, start, count, data, MPI_INT, nc_get_vara_int );
1089 #ifdef MOAB_HAVE_PNETCDF
1094 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1095 if( rc != NC_NOERR )
return rc;
1096 return ncmpi_get_vara_int_all( libId, varid, s, c, data );
1100 return nc_get_vara_int( libId, varid, start, count, data );
1103 int mbnc_get_vara_long(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
long* data )
1107 #ifdef MOAB_HAVE_MPI
1109 return bsuf_get_vara< long >( taggedFileId, varid, start, count, data, MPI_LONG, nc_get_vara_long );
1111 #ifdef MOAB_HAVE_PNETCDF
1116 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1117 if( rc != NC_NOERR )
return rc;
1118 return ncmpi_get_vara_long_all( libId, varid, s, c, data );
1122 return nc_get_vara_long( libId, varid, start, count, data );
1125 int mbnc_get_vara_text(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
char* data )
1129 #ifdef MOAB_HAVE_MPI
1131 return bsuf_get_vara< char >( taggedFileId, varid, start, count, data, MPI_CHAR, nc_get_vara_text );
1133 #ifdef MOAB_HAVE_PNETCDF
1138 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1139 if( rc != NC_NOERR )
return rc;
1140 return ncmpi_get_vara_text_all( libId, varid, s, c, data );
1144 return nc_get_vara_text( libId, varid, start, count, data );
1148 const ptrdiff_t* stride,
double* data )
1152 #ifdef MOAB_HAVE_MPI
1158 MPI_Comm comm = mbnc_buffered_comm( taggedFileId );
1159 const int rank = mbnc_buffered_rank( taggedFileId );
1160 const int size = mbnc_buffered_size( taggedFileId );
1163 if( rank == 0 ) rc = nc_inq_varndims( libId, varid, &ndims );
1164 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
1165 if( rc != NC_NOERR )
return rc;
1166 MPI_Bcast( &ndims, 1, MPI_INT, 0, comm );
1167 if( ndims >
kMaxDims )
return NC_EMAXDIMS;
1169 for(
int i = 0; i < ndims; ++i )
1173 int my_rc = nc_get_vars_double( libId, varid, start, count, stride, data );
1174 for(
int src = 1; src < size; ++src )
1178 MPI_Recv( s2, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 0, comm,
1179 MPI_STATUS_IGNORE );
1180 MPI_Recv( c2, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 1, comm,
1181 MPI_STATUS_IGNORE );
1182 MPI_Recv( st2, ndims *
static_cast< int >(
sizeof( ptrdiff_t ) ), MPI_BYTE, src, 4, comm,
1183 MPI_STATUS_IGNORE );
1185 for(
int i = 0; i < ndims; ++i )
1187 std::vector< double > buf( n );
1188 int s_rc = nc_get_vars_double( libId, varid, s2, c2, st2, buf.data() );
1189 MPI_Send( &s_rc, 1, MPI_INT, src, 2, comm );
1190 if( s_rc == NC_NOERR && n > 0 )
1191 MPI_Send( buf.data(),
static_cast< int >( n ), MPI_DOUBLE, src, 3, comm );
1197 MPI_Send( start, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 0, comm );
1198 MPI_Send( count, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 1, comm );
1199 MPI_Send( stride, ndims *
static_cast< int >(
sizeof( ptrdiff_t ) ), MPI_BYTE, 0, 4, comm );
1201 MPI_Recv( &recv_rc, 1, MPI_INT, 0, 2, comm, MPI_STATUS_IGNORE );
1202 if( recv_rc == NC_NOERR && my_n > 0 )
1203 MPI_Recv( data,
static_cast< int >( my_n ), MPI_DOUBLE, 0, 3, comm, MPI_STATUS_IGNORE );
1208 #ifdef MOAB_HAVE_PNETCDF
1213 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1214 if( rc != NC_NOERR )
return rc;
1215 for(
int i = 0; i < ndims; ++i )
1216 st[i] =
static_cast< MPI_Offset
>( stride[i] );
1217 return ncmpi_get_vars_double_all( libId, varid, s, c, st, data );
1221 return nc_get_vars_double( libId, varid, start, count, stride, data );
1228 int mbnc_put_vara_double(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const double* data )
1232 #ifdef MOAB_HAVE_PNETCDF
1237 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1238 if( rc != NC_NOERR )
return rc;
1239 return ncmpi_put_vara_double_all( libId, varid, s, c, data );
1243 return nc_put_vara_double( libId, varid, start, count, data );
1246 int mbnc_put_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const int* data )
1250 #ifdef MOAB_HAVE_PNETCDF
1255 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1256 if( rc != NC_NOERR )
return rc;
1257 return ncmpi_put_vara_int_all( libId, varid, s, c, data );
1261 return nc_put_vara_int( libId, varid, start, count, data );
1264 int mbnc_put_vara_text(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const char* data )
1268 #ifdef MOAB_HAVE_PNETCDF
1273 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1274 if( rc != NC_NOERR )
return rc;
1275 return ncmpi_put_vara_text_all( libId, varid, s, c, data );
1279 return nc_put_vara_text( libId, varid, start, count, data );
1295 #ifdef MOAB_HAVE_PNETCDF
1301 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1302 if( rc != NC_NOERR )
return rc;
1303 return ncmpi_iget_vara_double( libId, varid, s, c, data, req );
1311 int mbnc_iget_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
int* data,
int* req )
1314 #ifdef MOAB_HAVE_PNETCDF
1320 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1321 if( rc != NC_NOERR )
return rc;
1322 return ncmpi_iget_vara_int( libId, varid, s, c, data, req );
1340 #ifdef MOAB_HAVE_MPI
1342 return bsuf_get_vara< double >( taggedFileId, varid, start, count, data, MPI_DOUBLE, nc_get_vara_double );
1344 #ifdef MOAB_HAVE_PNETCDF
1349 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1350 if( rc != NC_NOERR )
return rc;
1351 return ncmpi_get_vara_double( libId, varid, s, c, data );
1355 return nc_get_vara_double( libId, varid, start, count, data );
1362 #ifdef MOAB_HAVE_MPI
1364 return bsuf_get_vara< int >( taggedFileId, varid, start, count, data, MPI_INT, nc_get_vara_int );
1366 #ifdef MOAB_HAVE_PNETCDF
1371 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1372 if( rc != NC_NOERR )
return rc;
1373 return ncmpi_get_vara_int( libId, varid, s, c, data );
1377 return nc_get_vara_int( libId, varid, start, count, data );
1384 #ifdef MOAB_HAVE_MPI
1386 return bsuf_get_vara< long >( taggedFileId, varid, start, count, data, MPI_LONG, nc_get_vara_long );
1388 #ifdef MOAB_HAVE_PNETCDF
1393 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1394 if( rc != NC_NOERR )
return rc;
1395 return ncmpi_get_vara_long( libId, varid, s, c, data );
1399 return nc_get_vara_long( libId, varid, start, count, data );
1406 #ifdef MOAB_HAVE_MPI
1408 return bsuf_get_vara< char >( taggedFileId, varid, start, count, data, MPI_CHAR, nc_get_vara_text );
1410 #ifdef MOAB_HAVE_PNETCDF
1415 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1416 if( rc != NC_NOERR )
return rc;
1417 return ncmpi_get_vara_text( libId, varid, s, c, data );
1421 return nc_get_vara_text( libId, varid, start, count, data );
1425 const ptrdiff_t* stride,
double* data )
1429 #ifdef MOAB_HAVE_MPI
1438 #ifdef MOAB_HAVE_PNETCDF
1443 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1444 if( rc != NC_NOERR )
return rc;
1445 for(
int i = 0; i < ndims; ++i )
1446 st[i] =
static_cast< MPI_Offset
>( stride[i] );
1447 return ncmpi_get_vars_double( libId, varid, s, c, st, data );
1451 return nc_get_vars_double( libId, varid, start, count, stride, data );
1455 const double* data )
1459 #ifdef MOAB_HAVE_PNETCDF
1464 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1465 if( rc != NC_NOERR )
return rc;
1466 return ncmpi_put_vara_double( libId, varid, s, c, data );
1470 return nc_put_vara_double( libId, varid, start, count, data );
1477 #ifdef MOAB_HAVE_PNETCDF
1482 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1483 if( rc != NC_NOERR )
return rc;
1484 return ncmpi_put_vara_int( libId, varid, s, c, data );
1488 return nc_put_vara_int( libId, varid, start, count, data );
1495 #ifdef MOAB_HAVE_PNETCDF
1500 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1501 if( rc != NC_NOERR )
return rc;
1502 return ncmpi_put_vara_text( libId, varid, s, c, data );
1506 return nc_put_vara_text( libId, varid, start, count, data );
1513 #ifdef MOAB_HAVE_PNETCDF
1519 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1520 if( rc != NC_NOERR )
return rc;
1521 return ncmpi_iput_vara_double( libId, varid, s, c, data, req );
1529 int mbnc_iput_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const int* data,
1533 #ifdef MOAB_HAVE_PNETCDF
1539 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1540 if( rc != NC_NOERR )
return rc;
1541 return ncmpi_iput_vara_int( libId, varid, s, c, data, req );
1552 #ifdef MOAB_HAVE_PNETCDF
1553 if( backend ==
NCB_PNETCDF )
return ncmpi_wait_all(
mbnc_lib_id( taggedFileId ), nreq, requests, statuses );
1560 for(
int i = 0; i < nreq; ++i )
1562 if( !requests || requests[i] ==
MBNC_REQ_NULL ) statuses[i] = NC_NOERR;