1*47c6ae99SBarry Smith #define PETSCDM_DLL 2*47c6ae99SBarry Smith 3*47c6ae99SBarry Smith /* 4*47c6ae99SBarry Smith Code for manipulating distributed regular arrays in parallel. 5*47c6ae99SBarry Smith */ 6*47c6ae99SBarry Smith 7*47c6ae99SBarry Smith #include "private/daimpl.h" /*I "petscda.h" I*/ 8*47c6ae99SBarry Smith 9*47c6ae99SBarry Smith #undef __FUNCT__ 10*47c6ae99SBarry Smith #define __FUNCT__ "DAGlobalToLocalBegin" 11*47c6ae99SBarry Smith /*@ 12*47c6ae99SBarry Smith DAGlobalToLocalBegin - Maps values from the global vector to the local 13*47c6ae99SBarry Smith patch; the ghost points are included. Must be followed by 14*47c6ae99SBarry Smith DAGlobalToLocalEnd() to complete the exchange. 15*47c6ae99SBarry Smith 16*47c6ae99SBarry Smith Neighbor-wise Collective on DA 17*47c6ae99SBarry Smith 18*47c6ae99SBarry Smith Input Parameters: 19*47c6ae99SBarry Smith + da - the distributed array context 20*47c6ae99SBarry Smith . g - the global vector 21*47c6ae99SBarry Smith - mode - one of INSERT_VALUES or ADD_VALUES 22*47c6ae99SBarry Smith 23*47c6ae99SBarry Smith Output Parameter: 24*47c6ae99SBarry Smith . l - the local values 25*47c6ae99SBarry Smith 26*47c6ae99SBarry Smith Level: beginner 27*47c6ae99SBarry Smith 28*47c6ae99SBarry Smith Notes: 29*47c6ae99SBarry Smith The global and local vectors used here need not be the same as those 30*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateLocalVector(), BUT they 31*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 32*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 33*47c6ae99SBarry Smith 34*47c6ae99SBarry Smith .keywords: distributed array, global to local, begin 35*47c6ae99SBarry Smith 36*47c6ae99SBarry Smith .seealso: DAGlobalToLocalEnd(), DALocalToGlobal(), DACreate2d(), 37*47c6ae99SBarry Smith DALocalToLocalBegin(), DALocalToLocalEnd(), 38*47c6ae99SBarry Smith DALocalToGlobalBegin(), DALocalToGlobalEnd() 39*47c6ae99SBarry Smith 40*47c6ae99SBarry Smith 41*47c6ae99SBarry Smith @*/ 42*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DAGlobalToLocalBegin(DA da,Vec g,InsertMode mode,Vec l) 43*47c6ae99SBarry Smith { 44*47c6ae99SBarry Smith PetscErrorCode ierr; 45*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 46*47c6ae99SBarry Smith 47*47c6ae99SBarry Smith PetscFunctionBegin; 48*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 49*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,2); 50*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,4); 51*47c6ae99SBarry Smith ierr = VecScatterBegin(dd->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 52*47c6ae99SBarry Smith PetscFunctionReturn(0); 53*47c6ae99SBarry Smith } 54*47c6ae99SBarry Smith 55*47c6ae99SBarry Smith #undef __FUNCT__ 56*47c6ae99SBarry Smith #define __FUNCT__ "DALocalToGlobalBegin" 57*47c6ae99SBarry Smith /*@ 58*47c6ae99SBarry Smith DALocalToGlobalBegin - Adds values from the local (ghosted) vector 59*47c6ae99SBarry Smith into the global (nonghosted) vector. 60*47c6ae99SBarry Smith 61*47c6ae99SBarry Smith Neighbor-wise Collective on DA 62*47c6ae99SBarry Smith 63*47c6ae99SBarry Smith Input Parameters: 64*47c6ae99SBarry Smith + da - the distributed array context 65*47c6ae99SBarry Smith - l - the local values 66*47c6ae99SBarry Smith 67*47c6ae99SBarry Smith Output Parameter: 68*47c6ae99SBarry Smith . g - the global vector 69*47c6ae99SBarry Smith 70*47c6ae99SBarry Smith Level: beginner 71*47c6ae99SBarry Smith 72*47c6ae99SBarry Smith Notes: 73*47c6ae99SBarry Smith Use DALocalToGlobal() to discard the ghost point values 74*47c6ae99SBarry Smith 75*47c6ae99SBarry Smith The global and local vectors used here need not be the same as those 76*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateLocalVector(), BUT they 77*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 78*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 79*47c6ae99SBarry Smith 80*47c6ae99SBarry Smith .keywords: distributed array, global to local, begin 81*47c6ae99SBarry Smith 82*47c6ae99SBarry Smith .seealso: DAGlobalToLocalEnd(), DALocalToGlobal(), DACreate2d(), 83*47c6ae99SBarry Smith DALocalToLocalBegin(), DALocalToLocalEnd(), DALocalToGlobalEnd() 84*47c6ae99SBarry Smith 85*47c6ae99SBarry Smith @*/ 86*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DALocalToGlobalBegin(DA da,Vec l,Vec g) 87*47c6ae99SBarry Smith { 88*47c6ae99SBarry Smith PetscErrorCode ierr; 89*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 90*47c6ae99SBarry Smith 91*47c6ae99SBarry Smith PetscFunctionBegin; 92*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 93*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,2); 94*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,3); 95*47c6ae99SBarry Smith ierr = VecScatterBegin(dd->gtol,l,g,ADD_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 96*47c6ae99SBarry Smith PetscFunctionReturn(0); 97*47c6ae99SBarry Smith } 98*47c6ae99SBarry Smith 99*47c6ae99SBarry Smith #undef __FUNCT__ 100*47c6ae99SBarry Smith #define __FUNCT__ "DALocalToGlobalEnd" 101*47c6ae99SBarry Smith /*@ 102*47c6ae99SBarry Smith DALocalToGlobalEnd - Adds values from the local (ghosted) vector 103*47c6ae99SBarry Smith into the global (nonghosted) vector. 104*47c6ae99SBarry Smith 105*47c6ae99SBarry Smith Neighbor-wise Collective on DA 106*47c6ae99SBarry Smith 107*47c6ae99SBarry Smith Input Parameters: 108*47c6ae99SBarry Smith + da - the distributed array context 109*47c6ae99SBarry Smith - l - the local values 110*47c6ae99SBarry Smith 111*47c6ae99SBarry Smith Output Parameter: 112*47c6ae99SBarry Smith . g - the global vector 113*47c6ae99SBarry Smith 114*47c6ae99SBarry Smith Level: beginner 115*47c6ae99SBarry Smith 116*47c6ae99SBarry Smith Notes: 117*47c6ae99SBarry Smith Use DALocalToGlobal() to discard the ghost point values 118*47c6ae99SBarry Smith 119*47c6ae99SBarry Smith The global and local vectors used here need not be the same as those 120*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateLocalVector(), BUT they 121*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 122*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 123*47c6ae99SBarry Smith 124*47c6ae99SBarry Smith .keywords: distributed array, global to local, begin 125*47c6ae99SBarry Smith 126*47c6ae99SBarry Smith .seealso: DAGlobalToLocalEnd(), DALocalToGlobal(), DACreate2d(), 127*47c6ae99SBarry Smith DALocalToLocalBegin(), DALocalToLocalEnd(), DALocalToGlobalBegin() 128*47c6ae99SBarry Smith 129*47c6ae99SBarry Smith @*/ 130*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DALocalToGlobalEnd(DA da,Vec l,Vec g) 131*47c6ae99SBarry Smith { 132*47c6ae99SBarry Smith PetscErrorCode ierr; 133*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 134*47c6ae99SBarry Smith 135*47c6ae99SBarry Smith PetscFunctionBegin; 136*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 137*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,2); 138*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,3); 139*47c6ae99SBarry Smith ierr = VecScatterEnd(dd->gtol,l,g,ADD_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 140*47c6ae99SBarry Smith PetscFunctionReturn(0); 141*47c6ae99SBarry Smith } 142*47c6ae99SBarry Smith 143*47c6ae99SBarry Smith #undef __FUNCT__ 144*47c6ae99SBarry Smith #define __FUNCT__ "DAGlobalToLocalEnd" 145*47c6ae99SBarry Smith /*@ 146*47c6ae99SBarry Smith DAGlobalToLocalEnd - Maps values from the global vector to the local 147*47c6ae99SBarry Smith patch; the ghost points are included. Must be preceeded by 148*47c6ae99SBarry Smith DAGlobalToLocalBegin(). 149*47c6ae99SBarry Smith 150*47c6ae99SBarry Smith Neighbor-wise Collective on DA 151*47c6ae99SBarry Smith 152*47c6ae99SBarry Smith Input Parameters: 153*47c6ae99SBarry Smith + da - the distributed array context 154*47c6ae99SBarry Smith . g - the global vector 155*47c6ae99SBarry Smith - mode - one of INSERT_VALUES or ADD_VALUES 156*47c6ae99SBarry Smith 157*47c6ae99SBarry Smith Output Parameter: 158*47c6ae99SBarry Smith . l - the local values 159*47c6ae99SBarry Smith 160*47c6ae99SBarry Smith Level: beginner 161*47c6ae99SBarry Smith 162*47c6ae99SBarry Smith Notes: 163*47c6ae99SBarry Smith The global and local vectors used here need not be the same as those 164*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateLocalVector(), BUT they 165*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 166*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 167*47c6ae99SBarry Smith 168*47c6ae99SBarry Smith .keywords: distributed array, global to local, end 169*47c6ae99SBarry Smith 170*47c6ae99SBarry Smith .seealso: DAGlobalToLocalBegin(), DALocalToGlobal(), DACreate2d(), 171*47c6ae99SBarry Smith DALocalToLocalBegin(), DALocalToLocalEnd(), DALocalToGlobalBegin(), DALocalToGlobalEnd() 172*47c6ae99SBarry Smith @*/ 173*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DAGlobalToLocalEnd(DA da,Vec g,InsertMode mode,Vec l) 174*47c6ae99SBarry Smith { 175*47c6ae99SBarry Smith PetscErrorCode ierr; 176*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 177*47c6ae99SBarry Smith 178*47c6ae99SBarry Smith PetscFunctionBegin; 179*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 180*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,2); 181*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,4); 182*47c6ae99SBarry Smith ierr = VecScatterEnd(dd->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 183*47c6ae99SBarry Smith PetscFunctionReturn(0); 184*47c6ae99SBarry Smith } 185*47c6ae99SBarry Smith 186*47c6ae99SBarry Smith EXTERN PetscErrorCode DAGetNatural_Private(DA,PetscInt*,IS*); 187*47c6ae99SBarry Smith #undef __FUNCT__ 188*47c6ae99SBarry Smith #define __FUNCT__ "DAGlobalToNatural_Create" 189*47c6ae99SBarry Smith /* 190*47c6ae99SBarry Smith DAGlobalToNatural_Create - Create the global to natural scatter object 191*47c6ae99SBarry Smith 192*47c6ae99SBarry Smith Collective on DA 193*47c6ae99SBarry Smith 194*47c6ae99SBarry Smith Input Parameter: 195*47c6ae99SBarry Smith . da - the distributed array context 196*47c6ae99SBarry Smith 197*47c6ae99SBarry Smith Level: developer 198*47c6ae99SBarry Smith 199*47c6ae99SBarry Smith Notes: This is an internal routine called by DAGlobalToNatural() to 200*47c6ae99SBarry Smith create the scatter context. 201*47c6ae99SBarry Smith 202*47c6ae99SBarry Smith .keywords: distributed array, global to local, begin 203*47c6ae99SBarry Smith 204*47c6ae99SBarry Smith .seealso: DAGlobalToNaturalBegin(), DAGlobalToNaturalEnd(), DALocalToGlobal(), DACreate2d(), 205*47c6ae99SBarry Smith DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DACreateNaturalVector() 206*47c6ae99SBarry Smith */ 207*47c6ae99SBarry Smith PetscErrorCode DAGlobalToNatural_Create(DA da) 208*47c6ae99SBarry Smith { 209*47c6ae99SBarry Smith PetscErrorCode ierr; 210*47c6ae99SBarry Smith PetscInt m,start,Nlocal; 211*47c6ae99SBarry Smith IS from,to; 212*47c6ae99SBarry Smith Vec global; 213*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 214*47c6ae99SBarry Smith 215*47c6ae99SBarry Smith PetscFunctionBegin; 216*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 217*47c6ae99SBarry Smith if (!dd->natural) { 218*47c6ae99SBarry Smith SETERRQ(((PetscObject)da)->comm,PETSC_ERR_ORDER,"Natural layout vector not yet created; cannot scatter into it"); 219*47c6ae99SBarry Smith } 220*47c6ae99SBarry Smith 221*47c6ae99SBarry Smith /* create the scatter context */ 222*47c6ae99SBarry Smith ierr = VecGetLocalSize(dd->natural,&m);CHKERRQ(ierr); 223*47c6ae99SBarry Smith ierr = VecGetOwnershipRange(dd->natural,&start,PETSC_NULL);CHKERRQ(ierr); 224*47c6ae99SBarry Smith 225*47c6ae99SBarry Smith ierr = DAGetNatural_Private(da,&Nlocal,&to);CHKERRQ(ierr); 226*47c6ae99SBarry Smith if (Nlocal != m) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Internal error: Nlocal %D local vector size %D",Nlocal,m); 227*47c6ae99SBarry Smith ierr = ISCreateStride(((PetscObject)da)->comm,m,start,1,&from);CHKERRQ(ierr); 228*47c6ae99SBarry Smith ierr = VecCreateMPIWithArray(((PetscObject)da)->comm,dd->Nlocal,PETSC_DETERMINE,0,&global); 229*47c6ae99SBarry Smith ierr = VecSetBlockSize(global,dd->w);CHKERRQ(ierr); 230*47c6ae99SBarry Smith ierr = VecScatterCreate(global,from,dd->natural,to,&dd->gton);CHKERRQ(ierr); 231*47c6ae99SBarry Smith ierr = VecDestroy(global);CHKERRQ(ierr); 232*47c6ae99SBarry Smith ierr = ISDestroy(from);CHKERRQ(ierr); 233*47c6ae99SBarry Smith ierr = ISDestroy(to);CHKERRQ(ierr); 234*47c6ae99SBarry Smith PetscFunctionReturn(0); 235*47c6ae99SBarry Smith } 236*47c6ae99SBarry Smith 237*47c6ae99SBarry Smith #undef __FUNCT__ 238*47c6ae99SBarry Smith #define __FUNCT__ "DAGlobalToNaturalBegin" 239*47c6ae99SBarry Smith /*@ 240*47c6ae99SBarry Smith DAGlobalToNaturalBegin - Maps values from the global vector to a global vector 241*47c6ae99SBarry Smith in the "natural" grid ordering. Must be followed by 242*47c6ae99SBarry Smith DAGlobalToNaturalEnd() to complete the exchange. 243*47c6ae99SBarry Smith 244*47c6ae99SBarry Smith Neighbor-wise Collective on DA 245*47c6ae99SBarry Smith 246*47c6ae99SBarry Smith Input Parameters: 247*47c6ae99SBarry Smith + da - the distributed array context 248*47c6ae99SBarry Smith . g - the global vector 249*47c6ae99SBarry Smith - mode - one of INSERT_VALUES or ADD_VALUES 250*47c6ae99SBarry Smith 251*47c6ae99SBarry Smith Output Parameter: 252*47c6ae99SBarry Smith . l - the natural ordering values 253*47c6ae99SBarry Smith 254*47c6ae99SBarry Smith Level: advanced 255*47c6ae99SBarry Smith 256*47c6ae99SBarry Smith Notes: 257*47c6ae99SBarry Smith The global and natrual vectors used here need not be the same as those 258*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateNaturalVector(), BUT they 259*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 260*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 261*47c6ae99SBarry Smith 262*47c6ae99SBarry Smith You must call DACreateNaturalVector() before using this routine 263*47c6ae99SBarry Smith 264*47c6ae99SBarry Smith .keywords: distributed array, global to local, begin 265*47c6ae99SBarry Smith 266*47c6ae99SBarry Smith .seealso: DAGlobalToNaturalEnd(), DALocalToGlobal(), DACreate2d(), 267*47c6ae99SBarry Smith DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DACreateNaturalVector(), 268*47c6ae99SBarry Smith DALocalToGlobalBegin(), DALocalToGlobalEnd() 269*47c6ae99SBarry Smith @*/ 270*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DAGlobalToNaturalBegin(DA da,Vec g,InsertMode mode,Vec l) 271*47c6ae99SBarry Smith { 272*47c6ae99SBarry Smith PetscErrorCode ierr; 273*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 274*47c6ae99SBarry Smith 275*47c6ae99SBarry Smith PetscFunctionBegin; 276*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 277*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,2); 278*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,4); 279*47c6ae99SBarry Smith if (!dd->gton) { 280*47c6ae99SBarry Smith /* create the scatter context */ 281*47c6ae99SBarry Smith ierr = DAGlobalToNatural_Create(da);CHKERRQ(ierr); 282*47c6ae99SBarry Smith } 283*47c6ae99SBarry Smith ierr = VecScatterBegin(dd->gton,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 284*47c6ae99SBarry Smith PetscFunctionReturn(0); 285*47c6ae99SBarry Smith } 286*47c6ae99SBarry Smith 287*47c6ae99SBarry Smith #undef __FUNCT__ 288*47c6ae99SBarry Smith #define __FUNCT__ "DAGlobalToNaturalEnd" 289*47c6ae99SBarry Smith /*@ 290*47c6ae99SBarry Smith DAGlobalToNaturalEnd - Maps values from the global vector to a global vector 291*47c6ae99SBarry Smith in the natural ordering. Must be preceeded by DAGlobalToNaturalBegin(). 292*47c6ae99SBarry Smith 293*47c6ae99SBarry Smith Neighbor-wise Collective on DA 294*47c6ae99SBarry Smith 295*47c6ae99SBarry Smith Input Parameters: 296*47c6ae99SBarry Smith + da - the distributed array context 297*47c6ae99SBarry Smith . g - the global vector 298*47c6ae99SBarry Smith - mode - one of INSERT_VALUES or ADD_VALUES 299*47c6ae99SBarry Smith 300*47c6ae99SBarry Smith Output Parameter: 301*47c6ae99SBarry Smith . l - the global values in the natural ordering 302*47c6ae99SBarry Smith 303*47c6ae99SBarry Smith Level: advanced 304*47c6ae99SBarry Smith 305*47c6ae99SBarry Smith Notes: 306*47c6ae99SBarry Smith The global and local vectors used here need not be the same as those 307*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateNaturalVector(), BUT they 308*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 309*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 310*47c6ae99SBarry Smith 311*47c6ae99SBarry Smith .keywords: distributed array, global to local, end 312*47c6ae99SBarry Smith 313*47c6ae99SBarry Smith .seealso: DAGlobalToNaturalBegin(), DALocalToGlobal(), DACreate2d(), 314*47c6ae99SBarry Smith DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DACreateNaturalVector(), 315*47c6ae99SBarry Smith DALocalToGlobalBegin(), DALocalToGlobalEnd() 316*47c6ae99SBarry Smith @*/ 317*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DAGlobalToNaturalEnd(DA da,Vec g,InsertMode mode,Vec l) 318*47c6ae99SBarry Smith { 319*47c6ae99SBarry Smith PetscErrorCode ierr; 320*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 321*47c6ae99SBarry Smith 322*47c6ae99SBarry Smith PetscFunctionBegin; 323*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 324*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,2); 325*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,4); 326*47c6ae99SBarry Smith ierr = VecScatterEnd(dd->gton,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr); 327*47c6ae99SBarry Smith PetscFunctionReturn(0); 328*47c6ae99SBarry Smith } 329*47c6ae99SBarry Smith 330*47c6ae99SBarry Smith #undef __FUNCT__ 331*47c6ae99SBarry Smith #define __FUNCT__ "DANaturalToGlobalBegin" 332*47c6ae99SBarry Smith /*@ 333*47c6ae99SBarry Smith DANaturalToGlobalBegin - Maps values from a global vector in the "natural" ordering 334*47c6ae99SBarry Smith to a global vector in the PETSc DA grid ordering. Must be followed by 335*47c6ae99SBarry Smith DANaturalToGlobalEnd() to complete the exchange. 336*47c6ae99SBarry Smith 337*47c6ae99SBarry Smith Neighbor-wise Collective on DA 338*47c6ae99SBarry Smith 339*47c6ae99SBarry Smith Input Parameters: 340*47c6ae99SBarry Smith + da - the distributed array context 341*47c6ae99SBarry Smith . g - the global vector in a natural ordering 342*47c6ae99SBarry Smith - mode - one of INSERT_VALUES or ADD_VALUES 343*47c6ae99SBarry Smith 344*47c6ae99SBarry Smith Output Parameter: 345*47c6ae99SBarry Smith . l - the values in the DA ordering 346*47c6ae99SBarry Smith 347*47c6ae99SBarry Smith Level: advanced 348*47c6ae99SBarry Smith 349*47c6ae99SBarry Smith Notes: 350*47c6ae99SBarry Smith The global and natural vectors used here need not be the same as those 351*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateNaturalVector(), BUT they 352*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 353*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 354*47c6ae99SBarry Smith 355*47c6ae99SBarry Smith .keywords: distributed array, global to local, begin 356*47c6ae99SBarry Smith 357*47c6ae99SBarry Smith .seealso: DAGlobalToNaturalEnd(), DAGlobalToNaturalBegin(), DALocalToGlobal(), DACreate2d(), 358*47c6ae99SBarry Smith DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DACreateNaturalVector(), 359*47c6ae99SBarry Smith DALocalToGlobalBegin(), DALocalToGlobalEnd() 360*47c6ae99SBarry Smith 361*47c6ae99SBarry Smith @*/ 362*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DANaturalToGlobalBegin(DA da,Vec g,InsertMode mode,Vec l) 363*47c6ae99SBarry Smith { 364*47c6ae99SBarry Smith PetscErrorCode ierr; 365*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 366*47c6ae99SBarry Smith 367*47c6ae99SBarry Smith PetscFunctionBegin; 368*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 369*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,2); 370*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,4); 371*47c6ae99SBarry Smith if (!dd->gton) { 372*47c6ae99SBarry Smith /* create the scatter context */ 373*47c6ae99SBarry Smith ierr = DAGlobalToNatural_Create(da);CHKERRQ(ierr); 374*47c6ae99SBarry Smith } 375*47c6ae99SBarry Smith ierr = VecScatterBegin(dd->gton,g,l,mode,SCATTER_REVERSE);CHKERRQ(ierr); 376*47c6ae99SBarry Smith PetscFunctionReturn(0); 377*47c6ae99SBarry Smith } 378*47c6ae99SBarry Smith 379*47c6ae99SBarry Smith #undef __FUNCT__ 380*47c6ae99SBarry Smith #define __FUNCT__ "DANaturalToGlobalEnd" 381*47c6ae99SBarry Smith /*@ 382*47c6ae99SBarry Smith DANaturalToGlobalEnd - Maps values from the natural ordering global vector 383*47c6ae99SBarry Smith to a global vector in the PETSc DA ordering. Must be preceeded by DANaturalToGlobalBegin(). 384*47c6ae99SBarry Smith 385*47c6ae99SBarry Smith Neighbor-wise Collective on DA 386*47c6ae99SBarry Smith 387*47c6ae99SBarry Smith Input Parameters: 388*47c6ae99SBarry Smith + da - the distributed array context 389*47c6ae99SBarry Smith . g - the global vector in a natural ordering 390*47c6ae99SBarry Smith - mode - one of INSERT_VALUES or ADD_VALUES 391*47c6ae99SBarry Smith 392*47c6ae99SBarry Smith Output Parameter: 393*47c6ae99SBarry Smith . l - the global values in the PETSc DA ordering 394*47c6ae99SBarry Smith 395*47c6ae99SBarry Smith Level: intermediate 396*47c6ae99SBarry Smith 397*47c6ae99SBarry Smith Notes: 398*47c6ae99SBarry Smith The global and local vectors used here need not be the same as those 399*47c6ae99SBarry Smith obtained from DACreateGlobalVector() and DACreateNaturalVector(), BUT they 400*47c6ae99SBarry Smith must have the same parallel data layout; they could, for example, be 401*47c6ae99SBarry Smith obtained with VecDuplicate() from the DA originating vectors. 402*47c6ae99SBarry Smith 403*47c6ae99SBarry Smith .keywords: distributed array, global to local, end 404*47c6ae99SBarry Smith 405*47c6ae99SBarry Smith .seealso: DAGlobalToNaturalBegin(), DAGlobalToNaturalEnd(), DALocalToGlobal(), DACreate2d(), 406*47c6ae99SBarry Smith DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DACreateNaturalVector(), 407*47c6ae99SBarry Smith DALocalToGlobalBegin(), DALocalToGlobalEnd() 408*47c6ae99SBarry Smith 409*47c6ae99SBarry Smith @*/ 410*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DANaturalToGlobalEnd(DA da,Vec g,InsertMode mode,Vec l) 411*47c6ae99SBarry Smith { 412*47c6ae99SBarry Smith PetscErrorCode ierr; 413*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 414*47c6ae99SBarry Smith 415*47c6ae99SBarry Smith PetscFunctionBegin; 416*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 417*47c6ae99SBarry Smith PetscValidHeaderSpecific(l,VEC_CLASSID,2); 418*47c6ae99SBarry Smith PetscValidHeaderSpecific(g,VEC_CLASSID,4); 419*47c6ae99SBarry Smith ierr = VecScatterEnd(dd->gton,g,l,mode,SCATTER_REVERSE);CHKERRQ(ierr); 420*47c6ae99SBarry Smith PetscFunctionReturn(0); 421*47c6ae99SBarry Smith } 422*47c6ae99SBarry Smith 423