1 #include <petsc-private/dmmbimpl.h> /*I "petscdm.h" I*/ 2 #include <petsc-private/vecimpl.h> /*I "petscdm.h" I*/ 3 4 #include <petscdmmoab.h> 5 #include <MBTagConventions.hpp> 6 7 // declare for use later but before they're defined 8 static PetscErrorCode DMMoab_VecUserDestroy(void *user); 9 static PetscErrorCode DMMoab_VecDuplicate(Vec x,Vec *y); 10 static PetscErrorCode DMMoab_VecCreateTagName_Private(moab::ParallelComm *pcomm,char** tag_name); 11 12 #undef __FUNCT__ 13 #define __FUNCT__ "DMMoab_CreateVector_Private" 14 PetscErrorCode DMMoab_CreateVector_Private(DM dm,moab::Tag tag,PetscInt tag_size,moab::Range* userrange,PetscBool is_global_vec,PetscBool destroy_tag,Vec *vec) 15 { 16 PetscErrorCode ierr; 17 moab::ErrorCode merr; 18 PetscBool is_newtag; 19 moab::Range *range; 20 PetscInt *gindices,*gsindices; 21 PetscInt i,count,icount,dof; 22 PetscInt size,rank; 23 std::string ttname; 24 PetscScalar *data_ptr; 25 26 Vec_MOAB *vmoab; 27 DM_Moab *dmmoab = (DM_Moab*)dm->data; 28 moab::ParallelComm *pcomm = dmmoab->pcomm; 29 moab::Interface *mbiface = dmmoab->mbiface; 30 moab::Tag ltog_tag = dmmoab->ltog_tag; 31 32 PetscFunctionBegin; 33 if(!userrange) range = dmmoab->vowned; 34 else range = userrange; 35 if(!range) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Input range cannot be empty or call DMSetUp first."); 36 37 merr = mbiface->tag_get_name(tag, ttname); 38 if (!ttname.length() && merr !=moab::MB_SUCCESS) { 39 /* get the new name for the anonymous MOABVec -> the tag_name will be destroyed along with Tag */ 40 char *tag_name = PETSC_NULL; 41 ierr = DMMoab_VecCreateTagName_Private(pcomm,&tag_name);CHKERRQ(ierr); 42 is_newtag = PETSC_TRUE; 43 44 /* Create the default value for the tag (all zeros) */ 45 std::vector<PetscScalar> default_value(tag_size, 0.0); 46 47 /* Create the tag */ 48 merr = mbiface->tag_get_handle(tag_name,tag_size,moab::MB_TYPE_DOUBLE,tag, 49 moab::MB_TAG_DENSE|moab::MB_TAG_CREAT,default_value.data());MBERRNM(merr); 50 ierr = PetscFree(tag_name);CHKERRQ(ierr); 51 } 52 else { 53 /* Make sure the tag data is of type "double" */ 54 moab::DataType tag_type; 55 merr = mbiface->tag_get_data_type(tag, tag_type);MBERRNM(merr); 56 if(tag_type != moab::MB_TYPE_DOUBLE) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Tag data type must be MB_TYPE_DOUBLE"); 57 is_newtag = destroy_tag; 58 } 59 60 /* Create the MOAB internal data object */ 61 ierr = PetscNew(Vec_MOAB,&vmoab);CHKERRQ(ierr); 62 vmoab->tag = tag; 63 vmoab->mbiface = mbiface; 64 vmoab->pcomm = pcomm; 65 vmoab->new_tag = is_newtag; 66 vmoab->is_global_vec = is_global_vec; 67 merr = mbiface->tag_get_length(tag,vmoab->tag_size);MBERR("tag_get_size", merr); 68 69 /* set the reference for vector range */ 70 vmoab->tag_range = new moab::Range(*range); 71 72 /* Call tag_iterate. This will cause MOAB to allocate memory for the 73 tag data if it hasn't already happened */ 74 merr = mbiface->tag_iterate(tag,range->begin(),range->end(),count,(void*&)data_ptr);MBERRNM(merr); 75 76 /* Check to make sure the tag data is in a single sequence */ 77 if ((unsigned)count != range->size()) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Can only create MOAB Vector for single sequence"); 78 79 ierr = MPI_Comm_size(((PetscObject)dm)->comm, &size);CHKERRQ(ierr); 80 ierr = MPI_Comm_rank(((PetscObject)dm)->comm, &rank);CHKERRQ(ierr); 81 82 /* Create the PETSc Vector 83 Query MOAB mesh to check if there are any ghosted entities 84 -> if we do, create a ghosted vector to map correctly to the same layout 85 -> else, create a non-ghosted parallel vector */ 86 if (!is_global_vec && (size>1) && dmmoab->nghost) { 87 moab::Range::iterator iter; 88 ierr = PetscMalloc(dmmoab->nghost*sizeof(PetscInt), &gsindices);CHKERRQ(ierr); 89 90 for(iter = dmmoab->vghost->begin(),icount=0; iter != dmmoab->vghost->end(); iter++) { 91 merr = mbiface->tag_get_data(ltog_tag,&(*iter),1,&dof);MBERRNM(merr); 92 gsindices[icount++] = dof; 93 } 94 95 /* This is an MPI Vector with ghosted padding */ 96 ierr = VecCreateGhostBlockWithArray(vmoab->pcomm->comm(),vmoab->tag_size,vmoab->tag_size*dmmoab->nloc, 97 vmoab->tag_size*dmmoab->n,dmmoab->nghost,gsindices,data_ptr,vec);CHKERRQ(ierr); 98 99 ierr = PetscFree(gsindices);CHKERRQ(ierr); 100 } 101 else if (size>1) { 102 /* This is an MPI Vector without ghosted padding */ 103 ierr = VecCreateMPIWithArray(vmoab->pcomm->comm(),vmoab->tag_size,vmoab->tag_size*range->size(), 104 PETSC_DECIDE,data_ptr,vec);CHKERRQ(ierr); 105 } 106 else { 107 /* This is a sequential vector - valid only for the single processor case since MOAB tags are always partitioned 108 and we cannot define a Vec using the Tag array with size>1 will be of full length */ 109 ierr = VecCreateSeqWithArray(PETSC_COMM_SELF,vmoab->tag_size,vmoab->tag_size*dmmoab->n,data_ptr,vec);CHKERRQ(ierr); 110 } 111 112 PetscContainer moabdata; 113 ierr = PetscContainerCreate(PETSC_COMM_SELF,&moabdata);CHKERRQ(ierr); 114 ierr = PetscContainerSetPointer(moabdata,vmoab);CHKERRQ(ierr); 115 ierr = PetscContainerSetUserDestroy(moabdata,DMMoab_VecUserDestroy);CHKERRQ(ierr); 116 ierr = PetscObjectCompose((PetscObject)*vec,"MOABData",(PetscObject)moabdata);CHKERRQ(ierr); 117 (*vec)->ops->duplicate = DMMoab_VecDuplicate; 118 ierr = PetscContainerDestroy(&moabdata);CHKERRQ(ierr); 119 120 if (!dmmoab->ltog_map) { 121 /* Vector created, manually set local to global mapping */ 122 ierr = PetscMalloc(range->size()*sizeof(PetscInt)*vmoab->tag_size, &gindices);CHKERRQ(ierr); 123 moab::Range::iterator iter; 124 for(iter = range->begin(),count=0; iter != range->end(); iter++,count+=vmoab->tag_size) { 125 merr = mbiface->tag_get_data(ltog_tag,&(*iter),1,&dof);MBERRNM(merr); 126 for(i=0; i<vmoab->tag_size; ++i) 127 gindices[count+i] = (dof)*vmoab->tag_size+i; 128 } 129 130 ierr = ISLocalToGlobalMappingCreate(PETSC_COMM_SELF,range->size(),gindices, 131 PETSC_COPY_VALUES,&dmmoab->ltog_map);CHKERRQ(ierr); 132 133 ierr = VecSetLocalToGlobalMappingBlock(*vec,dmmoab->ltog_map);CHKERRQ(ierr); 134 135 /* Clean up */ 136 ierr = PetscFree(gindices);CHKERRQ(ierr); 137 } 138 else { 139 ierr = VecSetLocalToGlobalMappingBlock(*vec,dmmoab->ltog_map);CHKERRQ(ierr); 140 } 141 142 /* set the DM reference to the vector */ 143 ierr = VecSetDM(*vec, dm);CHKERRQ(ierr); 144 PetscFunctionReturn(0); 145 } 146 147 148 #undef __FUNCT__ 149 #define __FUNCT__ "DMMoabCreateVector" 150 /*@ 151 DMMoabCreateVector - Create a Vec from either an existing tag, or a specified tag size, and a range of entities 152 153 Collective on MPI_Comm 154 155 Input Parameter: 156 . dm - The DMMoab object being set 157 . tag - If non-zero, block size will be taken from the tag size 158 . tag_size - If tag was zero, this parameter specifies the block size; unique tag name will be generated automatically 159 . range - If non-empty, Vec corresponds to these entities, otherwise to the entities set on the DMMoab 160 . is_global_vec - If true, this is a local representation of the Vec (including ghosts in parallel), otherwise a truly parallel one 161 . destroy_tag - If true, MOAB tag is destroyed with Vec, otherwise it is left on MOAB 162 163 Output Parameter: 164 . vec - The created vector 165 166 Level: beginner 167 168 .keywords: DMMoab, create 169 @*/ 170 PetscErrorCode DMMoabCreateVector(DM dm,moab::Tag tag,PetscInt tag_size,moab::Range* range,PetscBool is_global_vec,PetscBool destroy_tag,Vec *vec) 171 { 172 PetscErrorCode ierr; 173 174 PetscFunctionBegin; 175 if(!tag && !tag_size) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Both tag_size and tag cannot be null."); 176 177 ierr = DMMoab_CreateVector_Private(dm,tag,tag_size,range,is_global_vec,destroy_tag,vec);CHKERRQ(ierr); 178 PetscFunctionReturn(0); 179 } 180 181 182 #undef __FUNCT__ 183 #define __FUNCT__ "DMCreateGlobalVector_Moab" 184 PetscErrorCode DMCreateGlobalVector_Moab(DM dm,Vec *gvec) 185 { 186 PetscErrorCode ierr; 187 DM_Moab *dmmoab = (DM_Moab*)dm->data; 188 189 PetscFunctionBegin; 190 PetscValidHeaderSpecific(dm,DM_CLASSID,1); 191 PetscValidPointer(gvec,2); 192 ierr = DMMoab_CreateVector_Private(dm,PETSC_NULL,dmmoab->bs,dmmoab->vowned,PETSC_TRUE,PETSC_TRUE,gvec);CHKERRQ(ierr); 193 PetscFunctionReturn(0); 194 } 195 196 197 #undef __FUNCT__ 198 #define __FUNCT__ "DMCreateLocalVector_Moab" 199 PetscErrorCode DMCreateLocalVector_Moab(DM dm,Vec *lvec) 200 { 201 PetscErrorCode ierr; 202 moab::Range vlocal; 203 DM_Moab *dmmoab = (DM_Moab*)dm->data; 204 205 PetscFunctionBegin; 206 PetscValidHeaderSpecific(dm,DM_CLASSID,1); 207 PetscValidPointer(lvec,2); 208 vlocal = *dmmoab->vowned; 209 vlocal.merge(*dmmoab->vghost); 210 ierr = DMMoab_CreateVector_Private(dm,PETSC_NULL,dmmoab->bs,dmmoab->vowned,PETSC_FALSE,PETSC_TRUE,lvec);CHKERRQ(ierr); 211 PetscFunctionReturn(0); 212 } 213 214 215 #undef __FUNCT__ 216 #define __FUNCT__ "DMMoabGetVecTag" 217 /*@ 218 DMMoabGetVecTag - Get the MOAB tag associated with this Vec 219 220 Input Parameter: 221 . vec - Vec being queried 222 223 Output Parameter: 224 . tag - Tag associated with this Vec 225 226 Level: beginner 227 228 .keywords: DMMoab, create 229 @*/ 230 PetscErrorCode DMMoabGetVecTag(Vec vec,moab::Tag *tag) 231 { 232 PetscContainer moabdata; 233 Vec_MOAB *vmoab; 234 PetscErrorCode ierr; 235 236 PetscFunctionBegin; 237 PetscValidPointer(tag,2); 238 239 /* Get the MOAB private data */ 240 ierr = PetscObjectQuery((PetscObject)vec,"MOABData", (PetscObject*) &moabdata);CHKERRQ(ierr); 241 ierr = PetscContainerGetPointer(moabdata, (void**) &vmoab);CHKERRQ(ierr); 242 243 *tag = vmoab->tag; 244 PetscFunctionReturn(0); 245 } 246 247 248 #undef __FUNCT__ 249 #define __FUNCT__ "DMMoabGetVecRange" 250 /*@ 251 DMMoabGetVecRange - Get the MOAB entities associated with this Vec 252 253 Input Parameter: 254 . vec - Vec being queried 255 256 Output Parameter: 257 . range - Entities associated with this Vec 258 259 Level: beginner 260 261 .keywords: DMMoab, create 262 @*/ 263 PetscErrorCode DMMoabGetVecRange(Vec vec,moab::Range *range) 264 { 265 PetscContainer moabdata; 266 Vec_MOAB *vmoab; 267 PetscErrorCode ierr; 268 269 PetscFunctionBegin; 270 PetscValidPointer(range,2); 271 272 /* Get the MOAB private data handle */ 273 ierr = PetscObjectQuery((PetscObject)vec,"MOABData", (PetscObject*) &moabdata);CHKERRQ(ierr); 274 ierr = PetscContainerGetPointer(moabdata, (void**) &vmoab);CHKERRQ(ierr); 275 276 *range = *vmoab->tag_range; 277 PetscFunctionReturn(0); 278 } 279 280 281 #undef __FUNCT__ 282 #define __FUNCT__ "DMMoab_VecDuplicate" 283 PetscErrorCode DMMoab_VecDuplicate(Vec x,Vec *y) 284 { 285 PetscErrorCode ierr; 286 DM dm; 287 PetscContainer moabdata; 288 Vec_MOAB *vmoab; 289 290 PetscFunctionBegin; 291 PetscValidHeaderSpecific(x,VEC_CLASSID,1); 292 PetscValidPointer(y,2); 293 294 /* Get the Vec_MOAB struct for the original vector */ 295 ierr = PetscObjectQuery((PetscObject)x,"MOABData", (PetscObject*) &moabdata);CHKERRQ(ierr); 296 ierr = PetscContainerGetPointer(moabdata, (void**)&vmoab);CHKERRQ(ierr); 297 298 ierr = VecGetDM(x, &dm);CHKERRQ(ierr); 299 PetscValidHeaderSpecific(dm,DM_CLASSID,1); 300 301 ierr = DMMoab_CreateVector_Private(dm,PETSC_NULL,vmoab->tag_size,vmoab->tag_range,vmoab->is_global_vec,PETSC_TRUE,y);CHKERRQ(ierr); 302 ierr = VecSetDM(*y, dm);CHKERRQ(ierr); 303 PetscFunctionReturn(0); 304 } 305 306 307 #undef __FUNCT__ 308 #define __FUNCT__ "DMMoab_VecCreateTagName_Private" 309 /* DMMoab_VecCreateTagName_Private 310 * 311 * Creates a unique tag name that will be shared across processes. If 312 * pcomm is NULL, then this is a serial vector. A unique tag name 313 * will be returned in tag_name in either case. 314 * 315 * The tag names have the format _PETSC_VEC_N where N is some integer. 316 * 317 * NOTE: The tag_name is allocated in this routine; The user needs to free 318 * the character array. 319 */ 320 PetscErrorCode DMMoab_VecCreateTagName_Private(moab::ParallelComm *pcomm,char** tag_name) 321 { 322 moab::ErrorCode mberr; 323 PetscErrorCode ierr; 324 PetscInt n,global_n; 325 moab::Tag indexTag; 326 327 PetscFunctionBegin; 328 const char* PVEC_PREFIX = "__PETSC_VEC_"; 329 ierr = PetscMalloc(PETSC_MAX_PATH_LEN, tag_name);CHKERRQ(ierr); 330 331 /* Check to see if there are any PETSc vectors defined */ 332 moab::Interface *mbiface = pcomm->get_moab(); 333 moab::EntityHandle rootset = mbiface->get_root_set(); 334 335 /* Create a tag in MOAB mesh to index and keep track of number of Petsc vec tags */ 336 mberr = mbiface->tag_get_handle("__PETSC_VECS__",1,moab::MB_TYPE_INTEGER,indexTag, 337 moab::MB_TAG_SPARSE | moab::MB_TAG_CREAT,0);MBERRNM(mberr); 338 mberr = mbiface->tag_get_data(indexTag, &rootset, 1, &n); 339 if (mberr == moab::MB_TAG_NOT_FOUND) n=0; /* this is the first temporary vector */ 340 else MBERRNM(mberr); 341 342 /* increment the new value of n */ 343 ++n; 344 345 /* Make sure that n is consistent across all processes */ 346 ierr = MPI_Allreduce(&n,&global_n,1,MPI_INT,MPI_MAX,pcomm->comm());CHKERRQ(ierr); 347 348 /* Set the new name accordingly and return */ 349 ierr = PetscSNPrintf(*tag_name, PETSC_MAX_PATH_LEN-1, "%s_%D", PVEC_PREFIX, global_n);CHKERRQ(ierr); 350 mberr = mbiface->tag_set_data(indexTag, &rootset, 1, (const void*)&global_n);MBERRNM(mberr); 351 PetscFunctionReturn(0); 352 } 353 354 355 #undef __FUNCT__ 356 #define __FUNCT__ "DMMoab_VecUserDestroy" 357 PetscErrorCode DMMoab_VecUserDestroy(void *user) 358 { 359 Vec_MOAB *vmoab=(Vec_MOAB*)user; 360 PetscErrorCode ierr; 361 moab::ErrorCode merr; 362 363 PetscFunctionBegin; 364 if(vmoab->new_tag && vmoab->tag) { 365 /* Tag was created via a call to VecDuplicate, delete the underlying tag in MOAB */ 366 merr = vmoab->mbiface->tag_delete(vmoab->tag);MBERRNM(merr); 367 } 368 delete vmoab->tag_range; 369 vmoab->tag = PETSC_NULL; 370 vmoab->mbiface = PETSC_NULL; 371 vmoab->pcomm = PETSC_NULL; 372 ierr = PetscFree(vmoab);CHKERRQ(ierr); 373 PetscFunctionReturn(0); 374 } 375 376 #undef __FUNCT__ 377 #define __FUNCT__ "DMMoabVecGetArray" 378 /*@ 379 DMMoabVecGetArray - Returns the writable direct access array to the local representation of MOAB tag data for the underlying vector using locally owned+ghosted range of entities 380 381 Collective on MPI_Comm 382 383 Input Parameter: 384 . dm - The DMMoab object being set 385 . vec - The Vector whose underlying data is requested 386 387 Output Parameter: 388 . array - The local data array 389 390 Level: intermediate 391 392 .keywords: MOAB, distributed array 393 394 .seealso: DMMoabVecRestoreArray(), DMMoabVecGetArrayRead(), DMMoabVecRestoreArrayRead() 395 @*/ 396 PetscErrorCode DMMoabVecGetArray(DM dm,Vec vec,void* array) 397 { 398 DM_Moab *moab; 399 moab::ErrorCode merr; 400 PetscErrorCode ierr; 401 PetscInt count; 402 moab::Tag vtag; 403 PetscScalar **varray; 404 405 PetscFunctionBegin; 406 PetscValidHeaderSpecific(dm,DM_CLASSID,1); 407 PetscValidHeaderSpecific(vec,VEC_CLASSID,2); 408 moab=(DM_Moab*)dm->data; 409 410 /* Get the MOAB private data */ 411 ierr = DMMoabGetVecTag(vec,&vtag);CHKERRQ(ierr); 412 413 /* Get the real scalar array handle */ 414 varray = reinterpret_cast<PetscScalar**>(array); 415 416 /* Get the array data for local entities */ 417 merr = moab->mbiface->tag_iterate(vtag,moab->vlocal->begin(),moab->vlocal->end(),count,reinterpret_cast<void*&>(*varray),true);MBERRNM(merr); 418 if (count!=(PetscInt)moab->vlocal->size()) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Mismatch between local vertices and tag partition for Vec. %D != %D.",count,moab->vlocal->size()); 419 420 merr = moab->pcomm->exchange_tags(vtag,*moab->vlocal);MBERRNM(merr); 421 PetscFunctionReturn(0); 422 } 423 424 425 #undef __FUNCT__ 426 #define __FUNCT__ "DMMoabVecRestoreArray" 427 /*@ 428 DMMoabVecRestoreArray - Restores the writable direct access array obtained via DMMoabVecGetArray 429 430 Collective on MPI_Comm 431 432 Input Parameter: 433 + dm - The DMMoab object being set 434 . vec - The Vector whose underlying data is requested 435 - array - The local data array 436 437 Level: intermediate 438 439 .keywords: MOAB, distributed array 440 441 .seealso: DMMoabVecGetArray(), DMMoabVecGetArrayRead(), DMMoabVecRestoreArrayRead() 442 @*/ 443 PetscErrorCode DMMoabVecRestoreArray(DM dm,Vec v,void* array) 444 { 445 DM_Moab *moab; 446 moab::ErrorCode merr; 447 PetscErrorCode ierr; 448 moab::Tag vtag; 449 450 PetscFunctionBegin; 451 PetscValidHeaderSpecific(dm,DM_CLASSID,1); 452 PetscValidHeaderSpecific(v,VEC_CLASSID,2); 453 moab=(DM_Moab*)dm->data; 454 455 /* Get the MOAB private data */ 456 ierr = DMMoabGetVecTag(v,&vtag);CHKERRQ(ierr); 457 458 /* reduce the tags correctly -> should probably let the user choose how to reduce in the future 459 For all FEM residual based assembly calculations, MPI_SUM should serve well 460 */ 461 merr = moab->pcomm->reduce_tags(vtag,MPI_SUM,*moab->vghost);MBERRNM(merr); 462 PetscFunctionReturn(0); 463 } 464 465 #undef __FUNCT__ 466 #define __FUNCT__ "DMMoabVecGetArrayRead" 467 /*@ 468 DMMoabVecGetArrayRead - Returns the read-only direct access array to the local representation of MOAB tag data for the underlying vector using locally owned+ghosted range of entities 469 470 Collective on MPI_Comm 471 472 Input Parameter: 473 + dm - The DMMoab object being set 474 . vec - The Vector whose underlying data is requested 475 476 Output Parameter: 477 . array - The local data array 478 479 Level: intermediate 480 481 .keywords: MOAB, distributed array 482 483 .seealso: DMMoabVecRestoreArrayRead(), DMMoabVecGetArray(), DMMoabVecRestoreArray() 484 @*/ 485 PetscErrorCode DMMoabVecGetArrayRead(DM dm,Vec vec,void* array) 486 { 487 DM_Moab *moab; 488 moab::ErrorCode merr; 489 PetscErrorCode ierr; 490 PetscInt count; 491 moab::Tag vtag; 492 PetscScalar **varray; 493 494 PetscFunctionBegin; 495 PetscValidHeaderSpecific(dm,DM_CLASSID,1); 496 PetscValidHeaderSpecific(vec,VEC_CLASSID,2); 497 moab=(DM_Moab*)dm->data; 498 499 /* Get the MOAB private data */ 500 ierr = DMMoabGetVecTag(vec,&vtag);CHKERRQ(ierr); 501 502 /* Get the real scalar array handle */ 503 varray = reinterpret_cast<PetscScalar**>(array); 504 505 /* Get the array data for local entities */ 506 merr = moab->mbiface->tag_iterate(vtag,moab->vlocal->begin(),moab->vlocal->end(),count,reinterpret_cast<void*&>(*varray),true);MBERRNM(merr); 507 if (count!=(PetscInt)moab->vlocal->size()) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Mismatch between local vertices and tag partition for Vec. %D != %D.",count,moab->vlocal->size()); 508 509 merr = moab->pcomm->exchange_tags(vtag,*moab->vlocal);MBERRNM(merr); 510 PetscFunctionReturn(0); 511 } 512 513 514 #undef __FUNCT__ 515 #define __FUNCT__ "DMMoabVecRestoreArrayRead" 516 /*@ 517 DMMoabVecRestoreArray - Restores the read-only direct access array obtained via DMMoabVecGetArray 518 519 Collective on MPI_Comm 520 521 Input Parameter: 522 + dm - The DMMoab object being set 523 . vec - The Vector whose underlying data is requested 524 - array - The local data array 525 526 Level: intermediate 527 528 .keywords: MOAB, distributed array 529 530 .seealso: DMMoabVecGetArrayRead(), DMMoabVecGetArray(), DMMoabVecRestoreArray() 531 @*/ 532 PetscErrorCode DMMoabVecRestoreArrayRead(DM dm,Vec v,void* array) 533 { 534 PetscFunctionBegin; 535 /* Nothing to do -> do not free the array memory obtained from tag_iterate */ 536 PetscFunctionReturn(0); 537 } 538 539 540 #undef __FUNCT__ 541 #define __FUNCT__ "DMGlobalToLocalBegin_Moab" 542 PetscErrorCode DMGlobalToLocalBegin_Moab(DM dm,Vec g,InsertMode mode,Vec l) 543 { 544 PetscErrorCode ierr; 545 DM_Moab *dmmoab = (DM_Moab*)dm->data; 546 547 PetscFunctionBegin; 548 ierr = VecScatterBegin(dmmoab->ltog_sendrecv,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 549 PetscFunctionReturn(0); 550 } 551 552 553 #undef __FUNCT__ 554 #define __FUNCT__ "DMGlobalToLocalEnd_Moab" 555 PetscErrorCode DMGlobalToLocalEnd_Moab(DM dm,Vec g,InsertMode mode,Vec l) 556 { 557 PetscErrorCode ierr; 558 DM_Moab *dmmoab = (DM_Moab*)dm->data; 559 560 PetscFunctionBegin; 561 ierr = VecScatterEnd(dmmoab->ltog_sendrecv,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 562 PetscFunctionReturn(0); 563 } 564 565 566 #undef __FUNCT__ 567 #define __FUNCT__ "DMLocalToGlobalBegin_Moab" 568 PetscErrorCode DMLocalToGlobalBegin_Moab(DM dm,Vec l,InsertMode mode,Vec g) 569 { 570 PetscErrorCode ierr; 571 DM_Moab *dmmoab = (DM_Moab*)dm->data; 572 573 PetscFunctionBegin; 574 ierr = VecScatterBegin(dmmoab->ltog_sendrecv,l,g,mode,SCATTER_REVERSE);CHKERRQ(ierr); 575 PetscFunctionReturn(0); 576 } 577 578 579 #undef __FUNCT__ 580 #define __FUNCT__ "DMLocalToGlobalEnd_Moab" 581 PetscErrorCode DMLocalToGlobalEnd_Moab(DM dm,Vec l,InsertMode mode,Vec g) 582 { 583 PetscErrorCode ierr; 584 DM_Moab *dmmoab = (DM_Moab*)dm->data; 585 586 PetscFunctionBegin; 587 ierr = VecScatterEnd(dmmoab->ltog_sendrecv,l,g,mode,SCATTER_REVERSE);CHKERRQ(ierr); 588 PetscFunctionReturn(0); 589 } 590 591 592