7 #ifdef MOAB_HAVE_ZOLTAN
20 createGatherSet( false )
70 std::vector< std::string >& dimNames = readNC->
dimNames;
73 if( std::find( dimNames.begin(), dimNames.end(), std::string(
"vertexDegree" ) ) != dimNames.end() )
return true;
82 std::map< std::string, ReadNC::VarData >& varInfo =
_readNC->
varInfo;
85 std::vector< std::string >::iterator vit;
88 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"maxEdges" ) ) != dimNames.end() )
90 idx = vit - dimNames.begin();
101 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"Time" ) ) != dimNames.end() )
102 idx = vit - dimNames.begin();
103 else if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"time" ) ) != dimNames.end() )
104 idx = vit - dimNames.begin();
118 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nCells" ) ) != dimNames.end() )
119 idx = vit - dimNames.begin();
122 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nCells' dimension" );
128 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nEdges" ) ) != dimNames.end() )
129 idx = vit - dimNames.begin();
132 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nEdges' dimension" );
139 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertices" ) ) != dimNames.end() )
140 idx = vit - dimNames.begin();
143 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'nVertices' dimension" );
149 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertLevels" ) ) != dimNames.end() )
150 idx = vit - dimNames.begin();
153 std::cerr <<
"Warning: dimension nVertLevels not found in header.\nThe file may contain "
161 std::vector< unsigned int > opt_lev_dims;
164 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertLevelsP1" ) ) != dimNames.end() )
166 idx = vit - dimNames.begin();
167 opt_lev_dims.push_back( idx );
171 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nVertLevelsP2" ) ) != dimNames.end() )
173 idx = vit - dimNames.begin();
174 opt_lev_dims.push_back( idx );
178 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"nSoilLevels" ) ) != dimNames.end() )
180 idx = vit - dimNames.begin();
181 opt_lev_dims.push_back( idx );
184 std::map< std::string, ReadNC::VarData >::iterator vmit;
190 if( ( vmit = varInfo.find(
"xtime" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
199 tVals.push_back( (
double)t );
204 for( vmit = varInfo.begin(); vmit != varInfo.end(); ++vmit )
226 for(
unsigned int i = 0; i < opt_lev_dims.size(); i++ )
230 vd.
numLev = dimLens[opt_lev_dims[i]];
263 Tag numCellGroupsTag;
265 "Trouble getting __NUM_CELL_GROUPS tag" );
267 "Trouble getting data of __NUM_CELL_GROUPS tag" );
275 "Trouble getting local vertices in current file set" );
277 if( !local_verts.
empty() )
279 std::vector< int > gids( local_verts.
size() );
283 "Trouble getting local gid values of vertices" );
296 "Trouble getting local edges in current file set" );
298 if( !local_edges.
empty() )
300 std::vector< int > gids( local_edges.
size() );
304 "Trouble getting local gid values of edges" );
317 "Trouble getting local cells in current file set" );
319 if( !local_cells.
empty() )
321 std::vector< int > gids( local_cells.
size() );
325 "Trouble getting local gid values of cells" );
336 for( rit = local_cells.
begin(), i = 0; rit != local_cells.
end(); ++rit, i++ )
371 int shifted_rank = rank;
373 if( trivialPartitionShift > 0 ) shifted_rank = ( rank + trivialPartitionShift ) % procs;
382 int iextra =
nCells % procs;
386 start_cell_idx += std::min( shifted_rank, iextra );
391 MB_CHK_SET_ERR( redistribute_local_cells( start_cell_idx, myPcomm ),
392 "Failed to redistribute local cells after trivial partition" );
407 int nEdgesOnCellVarId;
408 int success =
NCFUNC( inq_varid )(
_fileId,
"nEdgesOnCell", &nEdgesOnCellVarId );
409 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nEdgesOnCell" );
410 std::vector< int > num_edges_on_local_cells(
nLocalCells );
411 #ifdef MOAB_HAVE_PNETCDF
413 std::vector< int > requests( nb_reads );
414 std::vector< int > statuss( nb_reads );
417 size_t indexInArray = 0;
427 #ifdef MOAB_HAVE_PNETCDF
428 success = NCFUNCREQG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
429 &( num_edges_on_local_cells[indexInArray] ), &requests[idxReq++] );
431 success =
NCFUNCAG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count,
432 &( num_edges_on_local_cells[indexInArray] ) );
434 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data in a loop" );
437 indexInArray += ( endh - starth + 1 );
440 #ifdef MOAB_HAVE_PNETCDF
442 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
443 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
447 int local_max_edges_per_cell =
448 *( std::max_element( num_edges_on_local_cells.begin(), num_edges_on_local_cells.end() ) );
455 int global_max_edges_per_cell;
457 MPI_Allreduce( &local_max_edges_per_cell, &global_max_edges_per_cell, 1, MPI_INT, MPI_MAX,
459 assert( local_max_edges_per_cell <= global_max_edges_per_cell );
461 if( 0 == rank ) dbgOut.
tprintf( 1,
" global_max_edges_per_cell = %d\n", global_max_edges_per_cell );
466 int verticesOnCellVarId;
467 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnCell", &verticesOnCellVarId );
468 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnCell" );
470 #ifdef MOAB_HAVE_PNETCDF
484 #ifdef MOAB_HAVE_PNETCDF
485 success = NCFUNCREQG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
486 &( vertices_on_local_cells[indexInArray] ), &requests[idxReq++] );
488 success =
NCFUNCAG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
489 &( vertices_on_local_cells[indexInArray] ) );
491 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data in a loop" );
497 #ifdef MOAB_HAVE_PNETCDF
499 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
500 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
506 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
508 int num_edges = num_edges_on_local_cells[local_cell_idx];
510 int last_vert_idx = vertices_on_local_cells[idx_in_local_vert_arr + num_edges - 1];
512 vertices_on_local_cells[idx_in_local_vert_arr + i] = last_vert_idx;
518 "Failed to create local vertices for MPAS mesh" );
524 "Failed to create local edges for MPAS mesh" );
528 if( noMixedElements )
531 "Failed to create padded local cells for MPAS mesh" );
536 "Failed to create local cells for MPAS mesh" );
540 Tag numCellGroupsTag = 0;
543 "Trouble creating __NUM_CELL_GROUPS tag" );
545 "Trouble setting data to __NUM_CELL_GROUPS tag" );
555 "Failed to create gather set vertices for MPAS mesh" );
561 "Failed to create gather set edges for MPAS mesh" );
565 if( noMixedElements )
568 "Failed to create padded gather set cells for MPAS mesh" );
573 "Failed to create gather set cells for MPAS mesh" );
581 std::vector< int >& tstep_nums )
593 "Trouble getting vertices in current file set" );
594 assert(
"Should only have a single vertex subrange, since they were read in one shot" && verts.
psize() == 1 );
599 "Trouble getting edges in current file set" );
604 "Trouble getting faces in current file set" );
613 "Trouble getting owned faces in current file set" );
621 for(
unsigned int i = 0; i < vdatas.size(); i++ )
628 assert( 3 == vdatas[i].varDims.size() || 2 == vdatas[i].varDims.size() );
631 assert(
tDim == vdatas[i].varDims[0] );
634 vdatas[i].readStarts.resize( 3 );
635 vdatas[i].readCounts.resize( 3 );
638 vdatas[i].readStarts[0] = 0;
639 vdatas[i].readCounts[0] = 1;
642 switch( vdatas[i].entLoc )
669 MB_SET_ERR( MB_FAILURE,
"Unexpected entity location type for variable " << vdatas[i].varName );
674 if( vdatas[i].numLev < 1 ) vdatas[i].numLev = 1;
675 vdatas[i].readStarts[2] = 0;
676 vdatas[i].readCounts[2] = vdatas[i].numLev;
680 for( std::size_t idx = 0; idx != 3; idx++ )
681 vdatas[i].sz *= vdatas[i].readCounts[idx];
683 for(
unsigned int t = 0; t < tstep_nums.size(); t++ )
685 dbgOut.
tprintf( 2,
"Reading variable %s, time step %d\n", vdatas[i].varName.c_str(), tstep_nums[t] );
687 if( tstep_nums[t] >= dimLens[
tDim] )
693 if( !vdatas[i].varTags[t] )
696 "Trouble getting tag for variable " << vdatas[i].varName );
704 vdatas[i].varDatas[t] = NULL;
708 assert( 1 == range->
psize() );
712 "Failed to iterate tag for variable " << vdatas[i].varName );
713 assert( (
unsigned)count == range->
size() );
714 vdatas[i].varDatas[t] = data;
722 #ifdef MOAB_HAVE_PNETCDF
723 ErrorCode NCHelperMPAS::read_ucd_variables_to_nonset_async( std::vector< ReadNC::VarData >& vdatas,
724 std::vector< int >& tstep_nums )
731 "Trouble allocating space to read non-set variables" );
735 Range* pLocalGid = NULL;
737 for(
unsigned int i = 0; i < vdatas.size(); i++ )
742 switch( vdatas[i].entLoc )
754 MB_SET_ERR( MB_FAILURE,
"Unexpected entity location type for variable " << vdatas[i].varName );
757 std::size_t sz = vdatas[i].sz;
759 for(
unsigned int t = 0; t < tstep_nums.size(); t++ )
763 size_t nb_reads = pLocalGid->
psize();
764 std::vector< int > requests( nb_reads ), statuss( nb_reads );
768 vdatas[i].readStarts[0] = tstep_nums[t];
770 switch( vdatas[i].varDataType )
775 std::vector< double > tmpdoubledata( sz );
782 size_t indexInDoubleArray = 0;
784 for( Range::pair_iterator pair_iter = pLocalGid->
pair_begin(); pair_iter != pLocalGid->
pair_end();
789 vdatas[i].readStarts[1] = (
NCDF_SIZE)( starth - 1 );
790 vdatas[i].readCounts[1] = (
NCDF_SIZE)( endh - starth + 1 );
795 NCFUNCREQG( _vara_double )(
_fileId, vdatas[i].varId, &( vdatas[i].readStarts[0] ),
796 &( vdatas[i].readCounts[0] ),
797 &( tmpdoubledata[indexInDoubleArray] ), &requests[idxReq++] );
800 "Failed to read double data in a loop for variable " << vdatas[i].varName );
803 indexInDoubleArray += ( endh - starth + 1 ) * 1 * vdatas[i].numLev;
805 assert( ic == pLocalGid->
psize() );
807 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
808 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
822 "Failed to iterate tag on owned faces" );
824 for(
int j = 0; j < count; j++ )
826 int global_cell_idx =
830 assert( local_cell_idx != -1 );
831 for(
int level = 0; level < vdatas[i].numLev; level++ )
832 ( (
double*)ptr )[j * vdatas[i].numLev + level] =
833 tmpdoubledata[local_cell_idx * vdatas[i].numLev + level];
841 void* data = vdatas[i].varDatas[t];
842 for( std::size_t idx = 0; idx != tmpdoubledata.size(); idx++ )
843 ( (
double*)data )[idx] = tmpdoubledata[idx];
849 MB_SET_ERR( MB_FAILURE,
"Unexpected data type for variable " << vdatas[i].varName );
857 dbgOut.
printf( 1,
"Read variables: %s", vdatas.begin()->varName.c_str() );
858 for(
unsigned int i = 1; i < vdatas.size(); i++ )
859 dbgOut.
printf( 1,
", %s ", vdatas[i].varName.c_str() );
867 std::vector< int >& tstep_nums )
874 "Trouble allocating space to read non-set variables" );
878 Range* pLocalGid = NULL;
880 for(
unsigned int i = 0; i < vdatas.size(); i++ )
885 switch( vdatas[i].entLoc )
897 MB_SET_ERR( MB_FAILURE,
"Unexpected entity location type for variable " << vdatas[i].varName );
900 std::size_t sz = vdatas[i].sz;
902 for(
unsigned int t = 0; t < tstep_nums.size(); t++ )
905 vdatas[i].readStarts[0] = tstep_nums[t];
907 switch( vdatas[i].varDataType )
912 std::vector< double > tmpdoubledata( sz );
919 size_t indexInDoubleArray = 0;
926 vdatas[i].readStarts[1] = (
NCDF_SIZE)( starth - 1 );
927 vdatas[i].readCounts[1] = (
NCDF_SIZE)( endh - starth + 1 );
929 success =
NCFUNCAG( _vara_double )(
_fileId, vdatas[i].varId, &( vdatas[i].readStarts[0] ),
930 &( vdatas[i].readCounts[0] ),
931 &( tmpdoubledata[indexInDoubleArray] ) );
934 "Failed to read double data in a loop for variable " << vdatas[i].varName );
937 indexInDoubleArray += ( endh - starth + 1 ) * 1 * vdatas[i].numLev;
939 assert( ic == pLocalGid->
psize() );
953 "Failed to iterate tag on owned faces" );
955 for(
int j = 0; j < count; j++ )
957 int global_cell_idx =
961 assert( local_cell_idx != -1 );
962 for(
int level = 0; level < vdatas[i].numLev; level++ )
963 ( (
double*)ptr )[j * vdatas[i].numLev + level] =
964 tmpdoubledata[local_cell_idx * vdatas[i].numLev + level];
972 void* data = vdatas[i].varDatas[t];
973 for( std::size_t idx = 0; idx != tmpdoubledata.size(); idx++ )
974 ( (
double*)data )[idx] = tmpdoubledata[idx];
980 MB_SET_ERR( MB_FAILURE,
"Unexpected data type for variable " << vdatas[i].varName );
988 dbgOut.
printf( 1,
"Read variables: %s", vdatas.begin()->varName.c_str() );
989 for(
unsigned int i = 1; i < vdatas.size(); i++ )
990 dbgOut.
printf( 1,
", %s ", vdatas[i].varName.c_str() );
1002 #ifdef MOAB_HAVE_ZOLTAN
1007 int success =
NCFUNC( inq_varid )(
_fileId,
"xCell", &xCellVarId );
1008 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of xCell" );
1012 success =
NCFUNCAG( _vara_double )(
_fileId, xCellVarId, &read_start, &read_count, &xCell[0] );
1013 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xCell data" );
1017 success =
NCFUNC( inq_varid )(
_fileId,
"yCell", &yCellVarId );
1018 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of yCell" );
1020 success =
NCFUNCAG( _vara_double )(
_fileId, yCellVarId, &read_start, &read_count, &yCell[0] );
1021 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yCell data" );
1025 success =
NCFUNC( inq_varid )(
_fileId,
"zCell", &zCellVarId );
1026 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of zCell" );
1028 success =
NCFUNCAG( _vara_double )(
_fileId, zCellVarId, &read_start, &read_count, &zCell[0] );
1029 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zCell data" );
1037 "Error in Zoltan partitioning" );
1069 std::vector< int > vertices_on_local_cells_sorted( vertices_on_local_cells );
1070 std::sort( vertices_on_local_cells_sorted.begin(), vertices_on_local_cells_sorted.end() );
1071 std::copy( vertices_on_local_cells_sorted.rbegin(), vertices_on_local_cells_sorted.rend(),
1079 std::vector< double* > arrays;
1084 "Failed to create local vertices" );
1089 "Failed to add local vertices to current file set" );
1096 "Failed to iterate global id tag on local vertices" );
1098 int* gid_data = (
int*)data;
1106 "Failed to iterate file id tag on local vertices" );
1108 int bytes_per_tag = 4;
1110 "Can't get number of bytes for file id tag" );
1111 if( 4 == bytes_per_tag )
1113 gid_data = (
int*)data;
1116 else if( 8 == bytes_per_tag )
1118 long* handle_tag_data = (
long*)data;
1123 #ifdef MOAB_HAVE_PNETCDF
1125 std::vector< int > requests( nb_reads );
1126 std::vector< int > statuss( nb_reads );
1131 double* xptr = arrays[0];
1133 int success =
NCFUNC( inq_varid )(
_fileId,
"xVertex", &xVertexVarId );
1134 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of xVertex" );
1135 size_t indexInArray = 0;
1145 #ifdef MOAB_HAVE_PNETCDF
1146 success = NCFUNCREQG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, &( xptr[indexInArray] ),
1147 &requests[idxReq++] );
1149 success =
NCFUNCAG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, &( xptr[indexInArray] ) );
1151 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xVertex data in a loop" );
1154 indexInArray += ( endh - starth + 1 );
1157 #ifdef MOAB_HAVE_PNETCDF
1159 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1160 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1164 double* yptr = arrays[1];
1166 success =
NCFUNC( inq_varid )(
_fileId,
"yVertex", &yVertexVarId );
1167 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of yVertex" );
1168 #ifdef MOAB_HAVE_PNETCDF
1181 #ifdef MOAB_HAVE_PNETCDF
1182 success = NCFUNCREQG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, &( yptr[indexInArray] ),
1183 &requests[idxReq++] );
1185 success =
NCFUNCAG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, &( yptr[indexInArray] ) );
1187 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yVertex data in a loop" );
1190 indexInArray += ( endh - starth + 1 );
1193 #ifdef MOAB_HAVE_PNETCDF
1195 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1196 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1200 double* zptr = arrays[2];
1202 success =
NCFUNC( inq_varid )(
_fileId,
"zVertex", &zVertexVarId );
1203 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of zVertex" );
1204 #ifdef MOAB_HAVE_PNETCDF
1217 #ifdef MOAB_HAVE_PNETCDF
1218 success = NCFUNCREQG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, &( zptr[indexInArray] ),
1219 &requests[idxReq++] );
1221 success =
NCFUNCAG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, &( zptr[indexInArray] ) );
1223 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zVertex data in a loop" );
1226 indexInArray += ( endh - starth + 1 );
1229 #ifdef MOAB_HAVE_PNETCDF
1231 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1232 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1239 const std::vector< int >& num_edges_on_local_cells )
1246 int edgesOnCellVarId;
1247 int success =
NCFUNC( inq_varid )(
_fileId,
"edgesOnCell", &edgesOnCellVarId );
1248 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of edgesOnCell" );
1251 dbgOut.
tprintf( 1,
" edges_on_local_cells.size() = %d\n", (
int)edges_on_local_cells.size() );
1253 #ifdef MOAB_HAVE_PNETCDF
1255 std::vector< int > requests( nb_reads );
1256 std::vector< int > statuss( nb_reads );
1259 size_t indexInArray = 0;
1270 #ifdef MOAB_HAVE_PNETCDF
1271 success = NCFUNCREQG( _vara_int )(
_fileId, edgesOnCellVarId, read_starts, read_counts,
1272 &( edges_on_local_cells[indexInArray] ), &requests[idxReq++] );
1274 success =
NCFUNCAG( _vara_int )(
_fileId, edgesOnCellVarId, read_starts, read_counts,
1275 &( edges_on_local_cells[indexInArray] ) );
1277 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read edgesOnCell data in a loop" );
1283 #ifdef MOAB_HAVE_PNETCDF
1285 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1286 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1291 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
1293 int num_edges = num_edges_on_local_cells[local_cell_idx];
1295 int last_edge_idx = edges_on_local_cells[idx_in_local_edge_arr + num_edges - 1];
1297 edges_on_local_cells[idx_in_local_edge_arr + i] = last_edge_idx;
1301 std::sort( edges_on_local_cells.begin(), edges_on_local_cells.end() );
1315 "Failed to create local edges" );
1320 "Failed to add local edges to current file set" );
1327 "Failed to iterate global id tag on local edges" );
1329 int* gid_data = (
int*)data;
1332 int verticesOnEdgeVarId;
1335 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnEdge", &verticesOnEdgeVarId );
1336 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnEdge" );
1338 int* vertices_on_local_edges = (
int*)conn_arr_edges;
1339 #ifdef MOAB_HAVE_PNETCDF
1341 requests.resize( nb_reads );
1342 statuss.resize( nb_reads );
1355 #ifdef MOAB_HAVE_PNETCDF
1356 success = NCFUNCREQG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts,
1357 &( vertices_on_local_edges[indexInArray] ), &requests[idxReq++] );
1359 success =
NCFUNCAG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts,
1360 &( vertices_on_local_edges[indexInArray] ) );
1362 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnEdge data in a loop" );
1365 indexInArray += ( endh - starth + 1 ) * 2;
1368 #ifdef MOAB_HAVE_PNETCDF
1370 success =
NCFUNC( wait_all )(
_fileId, requests.size(), &requests[0], &statuss[0] );
1371 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed on wait_all" );
1377 for(
int edge_vert =
nLocalEdges * 2 - 1; edge_vert >= 0; edge_vert-- )
1379 int global_vert_idx = vertices_on_local_edges[edge_vert];
1381 assert( local_vert_idx != -1 );
1382 conn_arr_edges[edge_vert] = start_vertex + local_vert_idx;
1389 const std::vector< int >& num_edges_on_local_cells,
1401 int num_edges = num_edges_on_local_cells[i];
1405 std::vector< int > num_edges_on_cell_groups;
1408 if( local_cells_with_n_edges[i].size() > 0 ) num_edges_on_cell_groups.push_back( i );
1415 int num_edges_per_cell = num_edges_on_cell_groups[i];
1416 int num_group_cells = (int)local_cells_with_n_edges[num_edges_per_cell].size();
1421 num_group_cells, num_edges_per_cell,
MBPOLYGON, 0, start_element,
1422 conn_arr_local_cells_with_n_edges[num_edges_per_cell], num_group_cells ),
1423 "Failed to create local cells" );
1424 faces.
insert( start_element, start_element + num_group_cells - 1 );
1427 Range local_cells_range( start_element, start_element + num_group_cells - 1 );
1429 "Failed to add local cells to current file set" );
1436 "Failed to iterate global id tag on local cells" );
1437 assert( count == num_group_cells );
1438 int* gid_data = (
int*)data;
1439 std::copy( local_cells_with_n_edges[num_edges_per_cell].begin(),
1440 local_cells_with_n_edges[num_edges_per_cell].end(), gid_data );
1443 for(
int j = 0; j < num_group_cells; j++ )
1446 local_cells_with_n_edges[num_edges_per_cell][j];
1448 assert( local_cell_idx != -1 );
1456 for(
int k = 0; k < num_edges_per_cell; k++ )
1461 assert( local_vert_idx != -1 );
1462 conn_arr_local_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
1463 start_vertex + local_vert_idx;
1488 "Failed to create local cells" );
1494 "Failed to add local cells to current file set" );
1501 "Failed to iterate global id tag on local cells" );
1503 int* gid_data = (
int*)data;
1509 for(
int local_cell_idx = 0; local_cell_idx <
nLocalCells; local_cell_idx++ )
1516 assert( local_vert_idx != -1 );
1517 conn_arr_local_cells[local_cell_idx *
maxEdgesPerCell + i] = start_vertex + local_vert_idx;
1531 std::vector< double* > arrays;
1535 "Failed to create gather set vertices" );
1538 Range gather_set_verts_range( gather_set_start_vertex, gather_set_start_vertex +
nVertices - 1 );
1540 "Failed to add vertices to the gather set" );
1543 double* xptr = arrays[0];
1545 int success =
NCFUNC( inq_varid )(
_fileId,
"xVertex", &xVertexVarId );
1546 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of xVertex" );
1549 #ifdef MOAB_HAVE_PNETCDF
1552 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1553 success =
NCFUNCG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, xptr );
1554 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xVertex data" );
1556 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1558 success =
NCFUNCG( _vara_double )(
_fileId, xVertexVarId, &read_start, &read_count, xptr );
1559 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read xVertex data" );
1563 double* yptr = arrays[1];
1565 success =
NCFUNC( inq_varid )(
_fileId,
"yVertex", &yVertexVarId );
1566 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of yVertex" );
1567 #ifdef MOAB_HAVE_PNETCDF
1570 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1571 success =
NCFUNCG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, yptr );
1572 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yVertex data" );
1574 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1576 success =
NCFUNCG( _vara_double )(
_fileId, yVertexVarId, &read_start, &read_count, yptr );
1577 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read yVertex data" );
1581 double* zptr = arrays[2];
1583 success =
NCFUNC( inq_varid )(
_fileId,
"zVertex", &zVertexVarId );
1584 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of zVertex" );
1585 #ifdef MOAB_HAVE_PNETCDF
1588 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1589 success =
NCFUNCG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, zptr );
1590 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zVertex data" );
1592 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1594 success =
NCFUNCG( _vara_double )(
_fileId, zVertexVarId, &read_start, &read_count, zptr );
1595 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read zVertex data" );
1603 "Failed to iterate global id tag on gather set vertices" );
1605 int* gid_data = (
int*)data;
1607 gid_data[j - 1] = j;
1614 "Failed to iterate file id tag on gather set vertices" );
1616 int bytes_per_tag = 4;
1618 "Can't get number of bytes for file id tag" );
1619 if( 4 == bytes_per_tag )
1621 gid_data = (
int*)data;
1625 else if( 8 == bytes_per_tag )
1627 long* handle_tag_data = (
long*)data;
1646 conn_arr_gather_set_edges ),
1647 "Failed to create gather set edges" );
1650 Range gather_set_edges_range( start_edge, start_edge +
nEdges - 1 );
1652 "Failed to add edges to the gather set" );
1655 int verticesOnEdgeVarId;
1656 int success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnEdge", &verticesOnEdgeVarId );
1657 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnEdge" );
1659 int* vertices_on_gather_set_edges = (
int*)conn_arr_gather_set_edges;
1662 #ifdef MOAB_HAVE_PNETCDF
1665 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1667 NCFUNCG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts, vertices_on_gather_set_edges );
1668 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnEdge data" );
1670 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1673 NCFUNCG( _vara_int )(
_fileId, verticesOnEdgeVarId, read_starts, read_counts, vertices_on_gather_set_edges );
1674 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnEdge data" );
1680 for(
int edge_vert =
nEdges * 2 - 1; edge_vert >= 0; edge_vert-- )
1682 int gather_set_vert_idx = vertices_on_gather_set_edges[edge_vert];
1683 gather_set_vert_idx--;
1685 conn_arr_gather_set_edges[edge_vert] = gather_set_start_vertex + gather_set_vert_idx;
1696 int nEdgesOnCellVarId;
1697 int success =
NCFUNC( inq_varid )(
_fileId,
"nEdgesOnCell", &nEdgesOnCellVarId );
1698 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nEdgesOnCell" );
1699 std::vector< int > num_edges_on_gather_set_cells(
nCells );
1702 #ifdef MOAB_HAVE_PNETCDF
1705 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1707 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1708 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1710 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1713 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1714 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1718 int verticesOnCellVarId;
1719 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnCell", &verticesOnCellVarId );
1720 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnCell" );
1724 #ifdef MOAB_HAVE_PNETCDF
1727 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1728 success =
NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
1729 &vertices_on_gather_set_cells[0] );
1730 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1732 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1734 success =
NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts,
1735 &vertices_on_gather_set_cells[0] );
1736 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1742 for(
int i =
nCells - 1; i >= 0; i-- )
1744 int num_edges = num_edges_on_gather_set_cells[i];
1745 gather_set_cells_with_n_edges[num_edges].
insert( i + 1 );
1750 for(
int num_edges_per_cell = 3; num_edges_per_cell <=
maxEdgesPerCell; num_edges_per_cell++ )
1752 int num_group_cells = gather_set_cells_with_n_edges[num_edges_per_cell].
size();
1753 if( num_group_cells > 0 )
1757 num_group_cells, num_edges_per_cell,
MBPOLYGON, 0, start_element,
1758 conn_arr_gather_set_cells_with_n_edges[num_edges_per_cell], num_group_cells ),
1759 "Failed to create gather set cells" );
1762 Range gather_set_cells_range( start_element, start_element + num_group_cells - 1 );
1764 "Failed to add cells to the gather set" );
1766 for(
int j = 0; j < num_group_cells; j++ )
1768 int gather_set_cell_idx =
1769 gather_set_cells_with_n_edges[num_edges_per_cell][j];
1770 gather_set_cell_idx--;
1772 for(
int k = 0; k < num_edges_per_cell; k++ )
1777 gather_set_vert_idx--;
1780 conn_arr_gather_set_cells_with_n_edges[num_edges_per_cell][j * num_edges_per_cell + k] =
1781 gather_set_start_vertex + gather_set_vert_idx;
1795 int nEdgesOnCellVarId;
1796 int success =
NCFUNC( inq_varid )(
_fileId,
"nEdgesOnCell", &nEdgesOnCellVarId );
1797 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of nEdgesOnCell" );
1798 std::vector< int > num_edges_on_gather_set_cells(
nCells );
1801 #ifdef MOAB_HAVE_PNETCDF
1804 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1806 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1807 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1809 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1812 NCFUNCG( _vara_int )(
_fileId, nEdgesOnCellVarId, &read_start, &read_count, &num_edges_on_gather_set_cells[0] );
1813 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read nEdgesOnCell data" );
1822 conn_arr_gather_set_cells ),
1823 "Failed to create gather set cells" );
1826 Range gather_set_cells_range( start_element, start_element +
nCells - 1 );
1828 "Failed to add cells to the gather set" );
1831 int verticesOnCellVarId;
1832 success =
NCFUNC( inq_varid )(
_fileId,
"verticesOnCell", &verticesOnCellVarId );
1833 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to get variable id of verticesOnCell" );
1835 int* vertices_on_gather_set_cells = (
int*)conn_arr_gather_set_cells;
1838 #ifdef MOAB_HAVE_PNETCDF
1841 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to begin independent I/O mode" );
1843 NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts, vertices_on_gather_set_cells );
1844 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1846 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to end independent I/O mode" );
1849 NCFUNCG( _vara_int )(
_fileId, verticesOnCellVarId, read_starts, read_counts, vertices_on_gather_set_cells );
1850 if( success )
MB_SET_ERR( MB_FAILURE,
"Failed to read verticesOnCell data" );
1855 for(
int gather_set_cell_idx = 0; gather_set_cell_idx <
nCells; gather_set_cell_idx++ )
1857 int num_edges = num_edges_on_gather_set_cells[gather_set_cell_idx];
1858 int idx_in_gather_set_vert_arr = gather_set_cell_idx *
maxEdgesPerCell;
1859 int last_vert_idx = vertices_on_gather_set_cells[idx_in_gather_set_vert_arr + num_edges - 1];
1861 vertices_on_gather_set_cells[idx_in_gather_set_vert_arr + i] = last_vert_idx;
1869 int gather_set_vert_idx = vertices_on_gather_set_cells[cell_vert];
1870 gather_set_vert_idx--;
1872 conn_arr_gather_set_cells[cell_vert] = gather_set_start_vertex + gather_set_vert_idx;