28 #if !defined( MOAB_HAVE_NETCDF ) && !defined( MOAB_HAVE_PNETCDF )
29 #error "MBNcDispatch requires MOAB_HAVE_NETCDF or MOAB_HAVE_PNETCDF."
35 #if defined( MOAB_HAVE_NETCDF )
36 #define MBNC_HAVE_SERIAL_NC 1
53 #if !defined( MOAB_HAVE_NETCDF )
54 inline int nc_open(
const char*,
int,
int* ) {
return NC_EBADID; }
55 inline int nc_create(
const char*,
int,
int* ) {
return NC_EBADID; }
56 inline int nc_close(
int ) {
return NC_EBADID; }
57 inline int nc_redef(
int ) {
return NC_EBADID; }
59 inline int nc_def_dim(
int,
const char*,
size_t,
int* ) {
return NC_EBADID; }
60 inline int nc_def_var(
int,
const char*, nc_type,
int,
const int*,
int* ) {
return NC_EBADID; }
64 inline int nc_inq_dimid(
int,
const char*,
int* ) {
return NC_EBADID; }
65 inline int nc_inq_dim(
int,
int,
char*,
size_t* ) {
return NC_EBADID; }
67 inline int nc_inq_varid(
int,
const char*,
int* ) {
return NC_EBADID; }
74 inline int nc_inq_att(
int,
int,
const char*, nc_type*,
size_t* ) {
return NC_EBADID; }
75 inline int nc_inq_attlen(
int,
int,
const char*,
size_t* ) {
return NC_EBADID; }
77 inline int nc_get_att_int(
int,
int,
const char*,
int* ) {
return NC_EBADID; }
82 inline int nc_put_att_text(
int,
int,
const char*,
size_t,
const char* ) {
return NC_EBADID; }
83 inline int nc_put_att_int(
int,
int,
const char*, nc_type,
size_t,
const int* ) {
return NC_EBADID; }
84 inline int nc_put_att_short(
int,
int,
const char*, nc_type,
size_t,
const short* ) {
return NC_EBADID; }
85 inline int nc_put_att_float(
int,
int,
const char*, nc_type,
size_t,
const float* ) {
return NC_EBADID; }
86 inline int nc_put_att_double(
int,
int,
const char*, nc_type,
size_t,
const double* ) {
return NC_EBADID; }
87 inline int nc_get_vara_text(
int,
int,
const size_t*,
const size_t*,
char* ) {
return NC_EBADID; }
88 inline int nc_get_vara_int(
int,
int,
const size_t*,
const size_t*,
int* ) {
return NC_EBADID; }
89 inline int nc_get_vara_long(
int,
int,
const size_t*,
const size_t*,
long* ) {
return NC_EBADID; }
90 inline int nc_get_vara_double(
int,
int,
const size_t*,
const size_t*,
double* ) {
return NC_EBADID; }
91 inline int nc_get_vars_double(
int,
int,
const size_t*,
const size_t*,
const ptrdiff_t*,
double* ) {
return NC_EBADID; }
92 inline int nc_put_vara_text(
int,
int,
const size_t*,
const size_t*,
const char* ) {
return NC_EBADID; }
93 inline int nc_put_vara_int(
int,
int,
const size_t*,
const size_t*,
const int* ) {
return NC_EBADID; }
94 inline int nc_put_vara_double(
int,
int,
const size_t*,
const size_t*,
const double* ) {
return NC_EBADID; }
109 #ifdef MOAB_HAVE_PNETCDF
113 inline int to_mpi_offset_pair(
int libId,
int varid,
const size_t* start,
const size_t* count, MPI_Offset* outStart,
114 MPI_Offset* outCount,
int* outNdims )
117 int rc = ncmpi_inq_varndims( libId, varid, &ndims );
118 if( rc != NC_NOERR )
return rc;
119 if( ndims >
kMaxDims )
return NC_EMAXDIMS;
120 for(
int i = 0; i < ndims; ++i )
122 outStart[i] =
static_cast< MPI_Offset
>( start[i] );
123 outCount[i] =
static_cast< MPI_Offset
>( count[i] );
141 std::map< int, BufferedCtx >& buffered_registry()
143 static std::map< int, BufferedCtx > reg;
159 inline int bsuf_bcast_int(
int taggedId,
int rc_root,
int value_root,
int* out )
161 MPI_Comm comm = mbnc_buffered_comm( taggedId );
162 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
163 if( rc_root != NC_NOERR )
return rc_root;
164 MPI_Bcast( &value_root, 1, MPI_INT, 0, comm );
165 if( out ) *out = value_root;
170 inline int bsuf_bcast_size(
int taggedId,
int rc_root,
size_t value_root,
size_t* out )
172 MPI_Comm comm = mbnc_buffered_comm( taggedId );
173 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
174 if( rc_root != NC_NOERR )
return rc_root;
175 MPI_Bcast( &value_root,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, comm );
176 if( out ) *out = value_root;
182 inline int bsuf_bcast_bytes(
int taggedId,
int rc_root,
char*
buffer,
int nbytes )
184 MPI_Comm comm = mbnc_buffered_comm( taggedId );
185 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
186 if( rc_root != NC_NOERR )
return rc_root;
187 if(
buffer && nbytes > 0 ) MPI_Bcast(
buffer, nbytes, MPI_BYTE, 0, comm );
192 inline int bsuf_bcast_int_array(
int taggedId,
int rc_root,
int* buf,
int n )
194 MPI_Comm comm = mbnc_buffered_comm( taggedId );
195 MPI_Bcast( &rc_root, 1, MPI_INT, 0, comm );
196 if( rc_root != NC_NOERR )
return rc_root;
197 if( buf && n > 0 ) MPI_Bcast( buf, n, MPI_INT, 0, comm );
207 template <
typename T,
typename Fn >
208 int bsuf_get_vara(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count, T* data,
209 MPI_Datatype mpi_type, Fn nc_get_fn )
211 MPI_Comm comm = mbnc_buffered_comm( taggedFileId );
212 const int rank = mbnc_buffered_rank( taggedFileId );
213 const int size = mbnc_buffered_size( taggedFileId );
220 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
221 if( rc != NC_NOERR )
return rc;
222 MPI_Bcast( &ndims, 1, MPI_INT, 0, comm );
223 if( ndims >
kMaxDims )
return NC_EMAXDIMS;
227 for(
int i = 0; i < ndims; ++i )
233 int my_rc = nc_get_fn( libId, varid, start, count, data );
237 for(
int src = 1; src < size; ++src )
240 MPI_Recv( srcStart, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 0, comm,
242 MPI_Recv( srcCount, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 1, comm,
245 for(
int i = 0; i < ndims; ++i )
247 std::vector< T > buf( n );
248 int s_rc = nc_get_fn( libId, varid, srcStart, srcCount, buf.data() );
249 MPI_Send( &s_rc, 1, MPI_INT, src, 2, comm );
250 if( s_rc == NC_NOERR && n > 0 ) MPI_Send( buf.data(),
static_cast< int >( n ), mpi_type, src, 3, comm );
257 MPI_Send( start, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 0, comm );
258 MPI_Send( count, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 1, comm );
260 MPI_Recv( &recv_rc, 1, MPI_INT, 0, 2, comm, MPI_STATUS_IGNORE );
261 if( recv_rc == NC_NOERR && my_n > 0 )
262 MPI_Recv( data,
static_cast< int >( my_n ), mpi_type, 0, 3, comm, MPI_STATUS_IGNORE );
276 std::FILE* fp = std::fopen( path,
"rb" );
279 unsigned char magic[8];
280 std::memset( magic, 0,
sizeof( magic ) );
281 const size_t nread = std::fread( magic, 1,
sizeof( magic ), fp );
287 if( magic[0] ==
'C' && magic[1] ==
'D' && magic[2] ==
'F' )
289 if( magic[3] == 0x01 || magic[3] == 0x02 || magic[3] == 0x05 )
return NCFMT_CLASSIC;
293 if( nread >= 8 && magic[0] == 0x89 && magic[1] ==
'H' && magic[2] ==
'D' && magic[3] ==
'F' && magic[4] == 0x0D &&
294 magic[5] == 0x0A && magic[6] == 0x1A && magic[7] == 0x0A )
311 #ifdef MOAB_HAVE_NETCDF
322 #ifdef MOAB_HAVE_PNETCDF
324 #elif defined( MOAB_HAVE_NETCDFPAR )
334 #ifdef MOAB_HAVE_NETCDFPAR
336 #elif defined( MOAB_HAVE_NETCDF )
358 void mbnc_register_buffered(
int taggedFileId, MPI_Comm comm )
362 MPI_Comm_rank( comm, &ctx.rank );
363 MPI_Comm_size( comm, &ctx.size );
364 buffered_registry()[taggedFileId] = ctx;
367 void mbnc_unregister_buffered(
int taggedFileId )
369 buffered_registry().erase( taggedFileId );
372 MPI_Comm mbnc_buffered_comm(
int taggedFileId )
374 auto it = buffered_registry().find( taggedFileId );
375 return ( it == buffered_registry().end() ) ? MPI_COMM_NULL : it->second.comm;
378 int mbnc_buffered_rank(
int taggedFileId )
380 auto it = buffered_registry().find( taggedFileId );
381 return ( it == buffered_registry().end() ) ? -1 : it->second.rank;
384 int mbnc_buffered_size(
int taggedFileId )
386 auto it = buffered_registry().find( taggedFileId );
387 return ( it == buffered_registry().end() ) ? 0 : it->second.size;
396 int mbnc_open_par(
NcBackend backend, MPI_Comm comm, MPI_Info info,
const char* path,
int omode,
int* taggedFileId )
403 #ifdef MOAB_HAVE_PNETCDF
405 rc = ncmpi_open( comm, path, omode, info, &libId );
408 #ifdef MOAB_HAVE_NETCDFPAR
410 rc = nc_open_par( path, omode | NC_MPIIO, comm, info, &libId );
416 MPI_Comm_rank( comm, &rank );
417 if( rank == 0 ) rc =
nc_open( path, omode, &libId );
418 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
424 mbnc_register_buffered( *taggedFileId, comm );
430 rc =
nc_open( path, omode, &libId );
440 int mbnc_create_par(
NcBackend backend, MPI_Comm comm, MPI_Info info,
const char* path,
int cmode,
int* taggedFileId )
447 #ifdef MOAB_HAVE_PNETCDF
449 rc = ncmpi_create( comm, path, cmode, info, &libId );
452 #ifdef MOAB_HAVE_NETCDFPAR
454 rc = nc_create_par( path, cmode | NC_MPIIO, comm, info, &libId );
459 MPI_Comm_rank( comm, &rank );
460 if( rank == 0 ) rc =
nc_create( path, cmode, &libId );
461 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
465 mbnc_register_buffered( *taggedFileId, comm );
481 int mbnc_open(
const char* path,
int omode,
int* taggedFileId )
484 #ifdef MOAB_HAVE_NETCDF
485 int rc =
nc_open( path, omode, &libId );
488 #elif defined( MOAB_HAVE_PNETCDF )
490 int rc = ncmpi_open( MPI_COMM_SELF, path, omode, MPI_INFO_NULL, &libId );
504 #ifdef MOAB_HAVE_NETCDF
505 int rc =
nc_create( path, cmode, &libId );
508 #elif defined( MOAB_HAVE_PNETCDF )
509 int rc = ncmpi_create( MPI_COMM_SELF, path, cmode, MPI_INFO_NULL, &libId );
528 #ifdef MOAB_HAVE_PNETCDF
530 rc = ncmpi_close( libId );
533 #ifdef MOAB_HAVE_NETCDFPAR
544 const int rank = mbnc_buffered_rank( taggedFileId );
545 if( rank == 0 ) rc =
nc_close( libId );
546 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
547 mbnc_unregister_buffered( taggedFileId );
566 #ifdef MOAB_HAVE_PNETCDF
567 if( backend ==
NCB_PNETCDF )
return ncmpi_redef( libId );
577 #ifdef MOAB_HAVE_PNETCDF
578 if( backend ==
NCB_PNETCDF )
return ncmpi_enddef( libId );
584 int mbnc_def_dim(
int taggedFileId,
const char* name,
size_t len,
int* dimid )
588 #ifdef MOAB_HAVE_PNETCDF
589 if( backend ==
NCB_PNETCDF )
return ncmpi_def_dim( libId, name,
static_cast< MPI_Offset
>( len ), dimid );
595 int mbnc_def_var(
int taggedFileId,
const char* name, nc_type xtype,
int ndims,
const int* dimids,
int* varid )
599 #ifdef MOAB_HAVE_PNETCDF
600 if( backend ==
NCB_PNETCDF )
return ncmpi_def_var( libId, name, xtype, ndims, dimids, varid );
603 return nc_def_var( libId, name, xtype, ndims, dimids, varid );
617 #ifdef MOAB_HAVE_PNETCDF
627 #ifdef MOAB_HAVE_PNETCDF
648 int rc = NC_NOERR, v = 0;
649 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_natts( libId, &v );
650 return bsuf_bcast_int( taggedFileId, rc, v, nattsp );
653 #ifdef MOAB_HAVE_PNETCDF
654 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_natts( libId, nattsp );
667 int rc = NC_NOERR, v = 0;
668 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_ndims( libId, &v );
669 return bsuf_bcast_int( taggedFileId, rc, v, ndimsp );
672 #ifdef MOAB_HAVE_PNETCDF
673 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_ndims( libId, ndimsp );
686 int rc = NC_NOERR, v = 0;
687 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_nvars( libId, &v );
688 return bsuf_bcast_int( taggedFileId, rc, v, nvarsp );
691 #ifdef MOAB_HAVE_PNETCDF
692 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_nvars( libId, nvarsp );
705 int rc = NC_NOERR, v = 0;
706 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_dimid( libId, name, &v );
707 return bsuf_bcast_int( taggedFileId, rc, v, dimidp );
710 #ifdef MOAB_HAVE_PNETCDF
711 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_dimid( libId, name, dimidp );
717 int mbnc_inq_dim(
int taggedFileId,
int dimid,
char* name,
size_t* lenp )
726 char nameBuf[NC_MAX_NAME + 1] = { 0 };
729 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_dim( libId, dimid, nameBuf, &len );
731 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
732 if( rc != NC_NOERR )
return rc;
733 if( name ) MPI_Bcast( nameBuf, NC_MAX_NAME + 1, MPI_BYTE, 0, mbnc_buffered_comm( taggedFileId ) );
734 MPI_Bcast( &len,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, mbnc_buffered_comm( taggedFileId ) );
735 if( name ) std::memcpy( name, nameBuf, NC_MAX_NAME + 1 );
736 if( lenp ) *lenp = len;
740 #ifdef MOAB_HAVE_PNETCDF
744 int rc = ncmpi_inq_dim( libId, dimid, name, &tmp );
745 if( lenp ) *lenp =
static_cast< size_t >( tmp );
750 return nc_inq_dim( libId, dimid, name, lenp );
762 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_dimlen( libId, dimid, &v );
763 return bsuf_bcast_size( taggedFileId, rc, v, lenp );
766 #ifdef MOAB_HAVE_PNETCDF
770 int rc = ncmpi_inq_dimlen( libId, dimid, &tmp );
771 if( lenp ) *lenp =
static_cast< size_t >( tmp );
786 int rc = NC_NOERR, v = 0;
787 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_varid( libId, name, &v );
788 return bsuf_bcast_int( taggedFileId, rc, v, varidp );
791 #ifdef MOAB_HAVE_PNETCDF
792 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varid( libId, name, varidp );
805 char nameBuf[NC_MAX_NAME + 1] = { 0 };
807 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_varname( libId, varid, nameBuf );
808 int rc2 = bsuf_bcast_bytes( taggedFileId, rc, nameBuf, NC_MAX_NAME + 1 );
809 if( rc2 == NC_NOERR && name ) std::memcpy( name, nameBuf, NC_MAX_NAME + 1 );
813 #ifdef MOAB_HAVE_PNETCDF
814 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varname( libId, varid, name );
828 int rc = NC_NOERR, v = 0;
829 if( mbnc_buffered_rank( taggedFileId ) == 0 )
833 v =
static_cast< int >( t );
836 int rc2 = bsuf_bcast_int( taggedFileId, rc, v, &out );
837 if( rc2 == NC_NOERR && xtypep ) *xtypep =
static_cast< nc_type
>( out );
841 #ifdef MOAB_HAVE_PNETCDF
842 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_vartype( libId, varid, xtypep );
855 int rc = NC_NOERR, v = 0;
856 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_varndims( libId, varid, &v );
857 return bsuf_bcast_int( taggedFileId, rc, v, ndimsp );
860 #ifdef MOAB_HAVE_PNETCDF
861 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varndims( libId, varid, ndimsp );
877 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_varndims( libId, varid, &ndims );
878 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
879 if( rc != NC_NOERR )
return rc;
880 MPI_Bcast( &ndims, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
881 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_vardimid( libId, varid, dimids );
882 return bsuf_bcast_int_array( taggedFileId, rc, dimids, ndims );
885 #ifdef MOAB_HAVE_PNETCDF
886 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_vardimid( libId, varid, dimids );
899 int rc = NC_NOERR, v = 0;
900 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_varnatts( libId, varid, &v );
901 return bsuf_bcast_int( taggedFileId, rc, v, nattsp );
904 #ifdef MOAB_HAVE_PNETCDF
905 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_varnatts( libId, varid, nattsp );
918 char nameBuf[NC_MAX_NAME + 1] = { 0 };
920 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_attname( libId, varid, attnum, nameBuf );
921 int rc2 = bsuf_bcast_bytes( taggedFileId, rc, nameBuf, NC_MAX_NAME + 1 );
922 if( rc2 == NC_NOERR && name ) std::memcpy( name, nameBuf, NC_MAX_NAME + 1 );
926 #ifdef MOAB_HAVE_PNETCDF
927 if( backend ==
NCB_PNETCDF )
return ncmpi_inq_attname( libId, varid, attnum, name );
933 int mbnc_inq_att(
int taggedFileId,
int varid,
const char* name, nc_type* xtypep,
size_t* lenp )
943 if( mbnc_buffered_rank( taggedFileId ) == 0 ) rc =
nc_inq_att( libId, varid, name, &t, &len );
944 MPI_Bcast( &rc, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
945 if( rc != NC_NOERR )
return rc;
946 int tInt =
static_cast< int >( t );
947 MPI_Bcast( &tInt, 1, MPI_INT, 0, mbnc_buffered_comm( taggedFileId ) );
948 MPI_Bcast( &len,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, mbnc_buffered_comm( taggedFileId ) );
949 if( xtypep ) *xtypep =
static_cast< nc_type
>( tInt );
950 if( lenp ) *lenp = len;
954 #ifdef MOAB_HAVE_PNETCDF
958 int rc = ncmpi_inq_att( libId, varid, name, xtypep, &tmp );
959 if( lenp ) *lenp =
static_cast< size_t >( tmp );
964 return nc_inq_att( libId, varid, name, xtypep, lenp );
979 template <
typename T,
typename Fn >
980 int bsuf_get_att(
int taggedFileId,
int varid,
const char* name, T* value, MPI_Datatype mpi_type, Fn nc_get_att_fn )
982 MPI_Comm comm = mbnc_buffered_comm( taggedFileId );
983 const int rank = mbnc_buffered_rank( taggedFileId );
990 if( rc == NC_NOERR ) rc = nc_get_att_fn( libId, varid, name, value );
992 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
993 if( rc != NC_NOERR )
return rc;
994 MPI_Bcast( &len,
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, comm );
995 if( value && len > 0 ) MPI_Bcast( value,
static_cast< int >( len ), mpi_type, 0, comm );
1005 #ifdef MOAB_HAVE_MPI
1008 #ifdef MOAB_HAVE_PNETCDF
1009 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_text( libId, varid, name, value );
1019 #ifdef MOAB_HAVE_MPI
1022 #ifdef MOAB_HAVE_PNETCDF
1023 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_int( libId, varid, name, value );
1033 #ifdef MOAB_HAVE_MPI
1035 return bsuf_get_att< short >( taggedFileId, varid, name, value, MPI_SHORT,
nc_get_att_short );
1037 #ifdef MOAB_HAVE_PNETCDF
1038 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_short( libId, varid, name, value );
1048 #ifdef MOAB_HAVE_MPI
1050 return bsuf_get_att< long >( taggedFileId, varid, name, value, MPI_LONG,
nc_get_att_long );
1052 #ifdef MOAB_HAVE_PNETCDF
1053 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_long( libId, varid, name, value );
1063 #ifdef MOAB_HAVE_MPI
1065 return bsuf_get_att< float >( taggedFileId, varid, name, value, MPI_FLOAT,
nc_get_att_float );
1067 #ifdef MOAB_HAVE_PNETCDF
1068 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_float( libId, varid, name, value );
1078 #ifdef MOAB_HAVE_MPI
1080 return bsuf_get_att< double >( taggedFileId, varid, name, value, MPI_DOUBLE,
nc_get_att_double );
1082 #ifdef MOAB_HAVE_PNETCDF
1083 if( backend ==
NCB_PNETCDF )
return ncmpi_get_att_double( libId, varid, name, value );
1093 int mbnc_put_att_text(
int taggedFileId,
int varid,
const char* name,
size_t len,
const char* value )
1097 #ifdef MOAB_HAVE_PNETCDF
1099 return ncmpi_put_att_text( libId, varid, name,
static_cast< MPI_Offset
>( len ), value );
1105 int mbnc_put_att_int(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const int* value )
1109 #ifdef MOAB_HAVE_PNETCDF
1111 return ncmpi_put_att_int( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1117 int mbnc_put_att_short(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const short* value )
1121 #ifdef MOAB_HAVE_PNETCDF
1123 return ncmpi_put_att_short( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1129 int mbnc_put_att_float(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const float* value )
1133 #ifdef MOAB_HAVE_PNETCDF
1135 return ncmpi_put_att_float( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1141 int mbnc_put_att_double(
int taggedFileId,
int varid,
const char* name, nc_type xtype,
size_t len,
const double* value )
1145 #ifdef MOAB_HAVE_PNETCDF
1147 return ncmpi_put_att_double( libId, varid, name, xtype,
static_cast< MPI_Offset
>( len ), value );
1161 #ifdef MOAB_HAVE_MPI
1163 return bsuf_get_vara< double >( taggedFileId, varid, start, count, data, MPI_DOUBLE,
nc_get_vara_double );
1165 #ifdef MOAB_HAVE_PNETCDF
1170 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1171 if( rc != NC_NOERR )
return rc;
1172 return ncmpi_get_vara_double_all( libId, varid, s, c, data );
1179 int mbnc_get_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
int* data )
1183 #ifdef MOAB_HAVE_MPI
1185 return bsuf_get_vara< int >( taggedFileId, varid, start, count, data, MPI_INT,
nc_get_vara_int );
1187 #ifdef MOAB_HAVE_PNETCDF
1192 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1193 if( rc != NC_NOERR )
return rc;
1194 return ncmpi_get_vara_int_all( libId, varid, s, c, data );
1201 int mbnc_get_vara_long(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
long* data )
1205 #ifdef MOAB_HAVE_MPI
1207 return bsuf_get_vara< long >( taggedFileId, varid, start, count, data, MPI_LONG,
nc_get_vara_long );
1209 #ifdef MOAB_HAVE_PNETCDF
1214 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1215 if( rc != NC_NOERR )
return rc;
1216 return ncmpi_get_vara_long_all( libId, varid, s, c, data );
1223 int mbnc_get_vara_text(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
char* data )
1227 #ifdef MOAB_HAVE_MPI
1229 return bsuf_get_vara< char >( taggedFileId, varid, start, count, data, MPI_CHAR,
nc_get_vara_text );
1231 #ifdef MOAB_HAVE_PNETCDF
1236 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1237 if( rc != NC_NOERR )
return rc;
1238 return ncmpi_get_vara_text_all( libId, varid, s, c, data );
1246 const ptrdiff_t* stride,
double* data )
1250 #ifdef MOAB_HAVE_MPI
1256 MPI_Comm comm = mbnc_buffered_comm( taggedFileId );
1257 const int rank = mbnc_buffered_rank( taggedFileId );
1258 const int size = mbnc_buffered_size( taggedFileId );
1262 MPI_Bcast( &rc, 1, MPI_INT, 0, comm );
1263 if( rc != NC_NOERR )
return rc;
1264 MPI_Bcast( &ndims, 1, MPI_INT, 0, comm );
1265 if( ndims >
kMaxDims )
return NC_EMAXDIMS;
1267 for(
int i = 0; i < ndims; ++i )
1272 for(
int src = 1; src < size; ++src )
1276 MPI_Recv( s2, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 0, comm,
1277 MPI_STATUS_IGNORE );
1278 MPI_Recv( c2, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, src, 1, comm,
1279 MPI_STATUS_IGNORE );
1280 MPI_Recv( st2, ndims *
static_cast< int >(
sizeof( ptrdiff_t ) ), MPI_BYTE, src, 4, comm,
1281 MPI_STATUS_IGNORE );
1283 for(
int i = 0; i < ndims; ++i )
1285 std::vector< double > buf( n );
1287 MPI_Send( &s_rc, 1, MPI_INT, src, 2, comm );
1288 if( s_rc == NC_NOERR && n > 0 )
1289 MPI_Send( buf.data(),
static_cast< int >( n ), MPI_DOUBLE, src, 3, comm );
1295 MPI_Send( start, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 0, comm );
1296 MPI_Send( count, ndims *
static_cast< int >(
sizeof(
size_t ) ), MPI_BYTE, 0, 1, comm );
1297 MPI_Send( stride, ndims *
static_cast< int >(
sizeof( ptrdiff_t ) ), MPI_BYTE, 0, 4, comm );
1299 MPI_Recv( &recv_rc, 1, MPI_INT, 0, 2, comm, MPI_STATUS_IGNORE );
1300 if( recv_rc == NC_NOERR && my_n > 0 )
1301 MPI_Recv( data,
static_cast< int >( my_n ), MPI_DOUBLE, 0, 3, comm, MPI_STATUS_IGNORE );
1306 #ifdef MOAB_HAVE_PNETCDF
1311 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1312 if( rc != NC_NOERR )
return rc;
1313 for(
int i = 0; i < ndims; ++i )
1314 st[i] =
static_cast< MPI_Offset
>( stride[i] );
1315 return ncmpi_get_vars_double_all( libId, varid, s, c, st, data );
1326 int mbnc_put_vara_double(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const double* data )
1330 #ifdef MOAB_HAVE_PNETCDF
1335 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1336 if( rc != NC_NOERR )
return rc;
1337 return ncmpi_put_vara_double_all( libId, varid, s, c, data );
1344 int mbnc_put_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const int* data )
1348 #ifdef MOAB_HAVE_PNETCDF
1353 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1354 if( rc != NC_NOERR )
return rc;
1355 return ncmpi_put_vara_int_all( libId, varid, s, c, data );
1362 int mbnc_put_vara_text(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const char* data )
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_put_vara_text_all( libId, varid, s, c, data );
1393 #ifdef MOAB_HAVE_PNETCDF
1399 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1400 if( rc != NC_NOERR )
return rc;
1401 return ncmpi_iget_vara_double( libId, varid, s, c, data, req );
1409 int mbnc_iget_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
int* data,
int* req )
1412 #ifdef MOAB_HAVE_PNETCDF
1418 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1419 if( rc != NC_NOERR )
return rc;
1420 return ncmpi_iget_vara_int( libId, varid, s, c, data, req );
1438 #ifdef MOAB_HAVE_MPI
1440 return bsuf_get_vara< double >( taggedFileId, varid, start, count, data, MPI_DOUBLE,
nc_get_vara_double );
1442 #ifdef MOAB_HAVE_PNETCDF
1447 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1448 if( rc != NC_NOERR )
return rc;
1449 return ncmpi_get_vara_double( libId, varid, s, c, data );
1460 #ifdef MOAB_HAVE_MPI
1462 return bsuf_get_vara< int >( taggedFileId, varid, start, count, data, MPI_INT,
nc_get_vara_int );
1464 #ifdef MOAB_HAVE_PNETCDF
1469 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1470 if( rc != NC_NOERR )
return rc;
1471 return ncmpi_get_vara_int( libId, varid, s, c, data );
1482 #ifdef MOAB_HAVE_MPI
1484 return bsuf_get_vara< long >( taggedFileId, varid, start, count, data, MPI_LONG,
nc_get_vara_long );
1486 #ifdef MOAB_HAVE_PNETCDF
1491 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1492 if( rc != NC_NOERR )
return rc;
1493 return ncmpi_get_vara_long( libId, varid, s, c, data );
1504 #ifdef MOAB_HAVE_MPI
1506 return bsuf_get_vara< char >( taggedFileId, varid, start, count, data, MPI_CHAR,
nc_get_vara_text );
1508 #ifdef MOAB_HAVE_PNETCDF
1513 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1514 if( rc != NC_NOERR )
return rc;
1515 return ncmpi_get_vara_text( libId, varid, s, c, data );
1523 const ptrdiff_t* stride,
double* data )
1527 #ifdef MOAB_HAVE_MPI
1536 #ifdef MOAB_HAVE_PNETCDF
1541 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1542 if( rc != NC_NOERR )
return rc;
1543 for(
int i = 0; i < ndims; ++i )
1544 st[i] =
static_cast< MPI_Offset
>( stride[i] );
1545 return ncmpi_get_vars_double( libId, varid, s, c, st, data );
1553 const double* data )
1557 #ifdef MOAB_HAVE_PNETCDF
1562 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1563 if( rc != NC_NOERR )
return rc;
1564 return ncmpi_put_vara_double( libId, varid, s, c, data );
1575 #ifdef MOAB_HAVE_PNETCDF
1580 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1581 if( rc != NC_NOERR )
return rc;
1582 return ncmpi_put_vara_int( libId, varid, s, c, data );
1593 #ifdef MOAB_HAVE_PNETCDF
1598 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1599 if( rc != NC_NOERR )
return rc;
1600 return ncmpi_put_vara_text( libId, varid, s, c, data );
1611 #ifdef MOAB_HAVE_PNETCDF
1617 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1618 if( rc != NC_NOERR )
return rc;
1619 return ncmpi_iput_vara_double( libId, varid, s, c, data, req );
1627 int mbnc_iput_vara_int(
int taggedFileId,
int varid,
const size_t* start,
const size_t* count,
const int* data,
1631 #ifdef MOAB_HAVE_PNETCDF
1637 int rc = to_mpi_offset_pair( libId, varid, start, count, s, c, &ndims );
1638 if( rc != NC_NOERR )
return rc;
1639 return ncmpi_iput_vara_int( libId, varid, s, c, data, req );
1650 #ifdef MOAB_HAVE_PNETCDF
1651 if( backend ==
NCB_PNETCDF )
return ncmpi_wait_all(
mbnc_lib_id( taggedFileId ), nreq, requests, statuses );
1658 for(
int i = 0; i < nreq; ++i )
1660 if( !requests || requests[i] ==
MBNC_REQ_NULL ) statuses[i] = NC_NOERR;