1*69ce434fSBarry Smith 2*69ce434fSBarry Smith /* 3*69ce434fSBarry Smith This file contains routines for basic map object implementation. 4*69ce434fSBarry Smith */ 5*69ce434fSBarry Smith 6*69ce434fSBarry Smith #include <petscvec.h> 7*69ce434fSBarry Smith #include <petsc-private/threadcommimpl.h> 8*69ce434fSBarry Smith #undef __FUNCT__ 9*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutCreate" 10*69ce434fSBarry Smith /*@C 11*69ce434fSBarry Smith PetscLayoutCreate - Allocates PetscLayout space and sets the map contents to the default. 12*69ce434fSBarry Smith 13*69ce434fSBarry Smith Collective on MPI_Comm 14*69ce434fSBarry Smith 15*69ce434fSBarry Smith Input Parameters: 16*69ce434fSBarry Smith + comm - the MPI communicator 17*69ce434fSBarry Smith - map - pointer to the map 18*69ce434fSBarry Smith 19*69ce434fSBarry Smith Level: developer 20*69ce434fSBarry Smith 21*69ce434fSBarry Smith Notes: Typical calling sequence 22*69ce434fSBarry Smith PetscLayoutCreate(MPI_Comm,PetscLayout *); 23*69ce434fSBarry Smith PetscLayoutSetBlockSize(PetscLayout,1); 24*69ce434fSBarry Smith PetscLayoutSetSize(PetscLayout,n) or PetscLayoutSetLocalSize(PetscLayout,N); 25*69ce434fSBarry Smith PetscLayoutSetUp(PetscLayout); 26*69ce434fSBarry Smith Optionally use any of the following: 27*69ce434fSBarry Smith PetscLayoutGetSize(PetscLayout,PetscInt *); or PetscLayoutGetLocalSize(PetscLayout,PetscInt *;) 28*69ce434fSBarry Smith PetscLayoutGetRange(PetscLayout,PetscInt *rstart,PetscInt *rend); or PetscLayoutGetRanges(PetscLayout,const PetscInt *range[]) 29*69ce434fSBarry Smith PetscLayoutDestroy(PetscLayout); 30*69ce434fSBarry Smith 31*69ce434fSBarry Smith The PetscLayout object and methods are intended to be used in the PETSc Vec and Mat implementions; it is often not needed in 32*69ce434fSBarry Smith user codes unless you really gain something in their use. 33*69ce434fSBarry Smith 34*69ce434fSBarry Smith Fortran Notes: 35*69ce434fSBarry Smith Not available from Fortran 36*69ce434fSBarry Smith 37*69ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutDestroy(), 38*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutSetUp() 39*69ce434fSBarry Smith 40*69ce434fSBarry Smith @*/ 41*69ce434fSBarry Smith PetscErrorCode PetscLayoutCreate(MPI_Comm comm,PetscLayout *map) 42*69ce434fSBarry Smith { 43*69ce434fSBarry Smith PetscErrorCode ierr; 44*69ce434fSBarry Smith 45*69ce434fSBarry Smith PetscFunctionBegin; 46*69ce434fSBarry Smith ierr = PetscNew(struct _n_PetscLayout,map);CHKERRQ(ierr); 47*69ce434fSBarry Smith 48*69ce434fSBarry Smith (*map)->comm = comm; 49*69ce434fSBarry Smith (*map)->bs = -1; 50*69ce434fSBarry Smith (*map)->n = -1; 51*69ce434fSBarry Smith (*map)->N = -1; 52*69ce434fSBarry Smith (*map)->range = 0; 53*69ce434fSBarry Smith (*map)->rstart = 0; 54*69ce434fSBarry Smith (*map)->rend = 0; 55*69ce434fSBarry Smith (*map)->trstarts = 0; 56*69ce434fSBarry Smith PetscFunctionReturn(0); 57*69ce434fSBarry Smith } 58*69ce434fSBarry Smith 59*69ce434fSBarry Smith /*@C 60*69ce434fSBarry Smith PetscLayoutDestroy - Frees a map object and frees its range if that exists. 61*69ce434fSBarry Smith 62*69ce434fSBarry Smith Collective on MPI_Comm 63*69ce434fSBarry Smith 64*69ce434fSBarry Smith Input Parameters: 65*69ce434fSBarry Smith . map - the PetscLayout 66*69ce434fSBarry Smith 67*69ce434fSBarry Smith Level: developer 68*69ce434fSBarry Smith 69*69ce434fSBarry Smith The PetscLayout object and methods are intended to be used in the PETSc Vec and Mat implementions; it is 70*69ce434fSBarry Smith recommended they not be used in user codes unless you really gain something in their use. 71*69ce434fSBarry Smith 72*69ce434fSBarry Smith Fortran Notes: 73*69ce434fSBarry Smith Not available from Fortran 74*69ce434fSBarry Smith 75*69ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutCreate(), 76*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutSetUp() 77*69ce434fSBarry Smith 78*69ce434fSBarry Smith @*/ 79*69ce434fSBarry Smith #undef __FUNCT__ 80*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutDestroy" 81*69ce434fSBarry Smith PetscErrorCode PetscLayoutDestroy(PetscLayout *map) 82*69ce434fSBarry Smith { 83*69ce434fSBarry Smith PetscErrorCode ierr; 84*69ce434fSBarry Smith 85*69ce434fSBarry Smith PetscFunctionBegin; 86*69ce434fSBarry Smith if (!*map) PetscFunctionReturn(0); 87*69ce434fSBarry Smith if (!(*map)->refcnt--) { 88*69ce434fSBarry Smith ierr = PetscFree((*map)->range);CHKERRQ(ierr); 89*69ce434fSBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*map)->mapping);CHKERRQ(ierr); 90*69ce434fSBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*map)->bmapping);CHKERRQ(ierr); 91*69ce434fSBarry Smith #if defined(PETSC_THREADCOMM_ACTIVE) 92*69ce434fSBarry Smith ierr = PetscFree((*map)->trstarts);CHKERRQ(ierr); 93*69ce434fSBarry Smith #endif 94*69ce434fSBarry Smith 95*69ce434fSBarry Smith ierr = PetscFree((*map));CHKERRQ(ierr); 96*69ce434fSBarry Smith } 97*69ce434fSBarry Smith *map = NULL; 98*69ce434fSBarry Smith PetscFunctionReturn(0); 99*69ce434fSBarry Smith } 100*69ce434fSBarry Smith 101*69ce434fSBarry Smith /*@C 102*69ce434fSBarry Smith PetscLayoutSetUp - given a map where you have set either the global or local 103*69ce434fSBarry Smith size sets up the map so that it may be used. 104*69ce434fSBarry Smith 105*69ce434fSBarry Smith Collective on MPI_Comm 106*69ce434fSBarry Smith 107*69ce434fSBarry Smith Input Parameters: 108*69ce434fSBarry Smith . map - pointer to the map 109*69ce434fSBarry Smith 110*69ce434fSBarry Smith Level: developer 111*69ce434fSBarry Smith 112*69ce434fSBarry Smith Notes: Typical calling sequence 113*69ce434fSBarry Smith PetscLayoutCreate(MPI_Comm,PetscLayout *); 114*69ce434fSBarry Smith PetscLayoutSetBlockSize(PetscLayout,1); 115*69ce434fSBarry Smith PetscLayoutSetSize(PetscLayout,n) or PetscLayoutSetLocalSize(PetscLayout,N); or both 116*69ce434fSBarry Smith PetscLayoutSetUp(PetscLayout); 117*69ce434fSBarry Smith PetscLayoutGetSize(PetscLayout,PetscInt *); 118*69ce434fSBarry Smith 119*69ce434fSBarry Smith 120*69ce434fSBarry Smith If the local size, global size are already set and range exists then this does nothing. 121*69ce434fSBarry Smith 122*69ce434fSBarry Smith Fortran Notes: 123*69ce434fSBarry Smith Not available from Fortran 124*69ce434fSBarry Smith 125*69ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutDestroy(), 126*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutCreate() 127*69ce434fSBarry Smith 128*69ce434fSBarry Smith @*/ 129*69ce434fSBarry Smith #undef __FUNCT__ 130*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetUp" 131*69ce434fSBarry Smith PetscErrorCode PetscLayoutSetUp(PetscLayout map) 132*69ce434fSBarry Smith { 133*69ce434fSBarry Smith PetscMPIInt rank,size; 134*69ce434fSBarry Smith PetscInt p; 135*69ce434fSBarry Smith PetscErrorCode ierr; 136*69ce434fSBarry Smith 137*69ce434fSBarry Smith PetscFunctionBegin; 138*69ce434fSBarry Smith if (map->bs <= 0) map->bs = 1; 139*69ce434fSBarry Smith if ((map->n >= 0) && (map->N >= 0) && (map->range)) PetscFunctionReturn(0); 140*69ce434fSBarry Smith 141*69ce434fSBarry Smith ierr = MPI_Comm_size(map->comm, &size);CHKERRQ(ierr); 142*69ce434fSBarry Smith ierr = MPI_Comm_rank(map->comm, &rank);CHKERRQ(ierr); 143*69ce434fSBarry Smith if (map->n > 0) map->n = map->n/map->bs; 144*69ce434fSBarry Smith if (map->N > 0) map->N = map->N/map->bs; 145*69ce434fSBarry Smith ierr = PetscSplitOwnership(map->comm,&map->n,&map->N);CHKERRQ(ierr); 146*69ce434fSBarry Smith map->n = map->n*map->bs; 147*69ce434fSBarry Smith map->N = map->N*map->bs; 148*69ce434fSBarry Smith if (!map->range) { 149*69ce434fSBarry Smith ierr = PetscMalloc((size+1)*sizeof(PetscInt), &map->range);CHKERRQ(ierr); 150*69ce434fSBarry Smith } 151*69ce434fSBarry Smith ierr = MPI_Allgather(&map->n, 1, MPIU_INT, map->range+1, 1, MPIU_INT, map->comm);CHKERRQ(ierr); 152*69ce434fSBarry Smith 153*69ce434fSBarry Smith map->range[0] = 0; 154*69ce434fSBarry Smith for (p = 2; p <= size; p++) map->range[p] += map->range[p-1]; 155*69ce434fSBarry Smith 156*69ce434fSBarry Smith map->rstart = map->range[rank]; 157*69ce434fSBarry Smith map->rend = map->range[rank+1]; 158*69ce434fSBarry Smith #if defined(PETSC_THREADCOMM_ACTIVE) 159*69ce434fSBarry Smith /* Set the thread ownership ranges */ 160*69ce434fSBarry Smith ierr = PetscThreadCommGetOwnershipRanges(map->comm,map->n,&map->trstarts);CHKERRQ(ierr); 161*69ce434fSBarry Smith #endif 162*69ce434fSBarry Smith PetscFunctionReturn(0); 163*69ce434fSBarry Smith } 164*69ce434fSBarry Smith 165*69ce434fSBarry Smith #undef __FUNCT__ 166*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutDuplicate" 167*69ce434fSBarry Smith /*@C 168*69ce434fSBarry Smith 169*69ce434fSBarry Smith PetscLayoutDuplicate - creates a new PetscLayout with the same information as a given one. If the PetscLayout already exists it is destroyed first. 170*69ce434fSBarry Smith 171*69ce434fSBarry Smith Collective on PetscLayout 172*69ce434fSBarry Smith 173*69ce434fSBarry Smith Input Parameter: 174*69ce434fSBarry Smith . in - input PetscLayout to be duplicated 175*69ce434fSBarry Smith 176*69ce434fSBarry Smith Output Parameter: 177*69ce434fSBarry Smith . out - the copy 178*69ce434fSBarry Smith 179*69ce434fSBarry Smith Level: developer 180*69ce434fSBarry Smith 181*69ce434fSBarry Smith Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout 182*69ce434fSBarry Smith 183*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutReference() 184*69ce434fSBarry Smith 185*69ce434fSBarry Smith @*/ 186*69ce434fSBarry Smith PetscErrorCode PetscLayoutDuplicate(PetscLayout in,PetscLayout *out) 187*69ce434fSBarry Smith { 188*69ce434fSBarry Smith PetscMPIInt size; 189*69ce434fSBarry Smith PetscErrorCode ierr; 190*69ce434fSBarry Smith MPI_Comm comm = in->comm; 191*69ce434fSBarry Smith 192*69ce434fSBarry Smith PetscFunctionBegin; 193*69ce434fSBarry Smith ierr = PetscLayoutDestroy(out);CHKERRQ(ierr); 194*69ce434fSBarry Smith ierr = PetscLayoutCreate(comm,out);CHKERRQ(ierr); 195*69ce434fSBarry Smith ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 196*69ce434fSBarry Smith ierr = PetscMemcpy(*out,in,sizeof(struct _n_PetscLayout));CHKERRQ(ierr); 197*69ce434fSBarry Smith ierr = PetscMalloc((size+1)*sizeof(PetscInt),&(*out)->range);CHKERRQ(ierr); 198*69ce434fSBarry Smith ierr = PetscMemcpy((*out)->range,in->range,(size+1)*sizeof(PetscInt));CHKERRQ(ierr); 199*69ce434fSBarry Smith 200*69ce434fSBarry Smith (*out)->refcnt = 0; 201*69ce434fSBarry Smith PetscFunctionReturn(0); 202*69ce434fSBarry Smith } 203*69ce434fSBarry Smith 204*69ce434fSBarry Smith #undef __FUNCT__ 205*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutReference" 206*69ce434fSBarry Smith /*@C 207*69ce434fSBarry Smith 208*69ce434fSBarry Smith PetscLayoutReference - Causes a PETSc Vec or Mat to share a PetscLayout with one that already exists. Used by Vec/MatDuplicate_XXX() 209*69ce434fSBarry Smith 210*69ce434fSBarry Smith Collective on PetscLayout 211*69ce434fSBarry Smith 212*69ce434fSBarry Smith Input Parameter: 213*69ce434fSBarry Smith . in - input PetscLayout to be copied 214*69ce434fSBarry Smith 215*69ce434fSBarry Smith Output Parameter: 216*69ce434fSBarry Smith . out - the reference location 217*69ce434fSBarry Smith 218*69ce434fSBarry Smith Level: developer 219*69ce434fSBarry Smith 220*69ce434fSBarry Smith Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout 221*69ce434fSBarry Smith 222*69ce434fSBarry Smith If the out location already contains a PetscLayout it is destroyed 223*69ce434fSBarry Smith 224*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate() 225*69ce434fSBarry Smith 226*69ce434fSBarry Smith @*/ 227*69ce434fSBarry Smith PetscErrorCode PetscLayoutReference(PetscLayout in,PetscLayout *out) 228*69ce434fSBarry Smith { 229*69ce434fSBarry Smith PetscErrorCode ierr; 230*69ce434fSBarry Smith 231*69ce434fSBarry Smith PetscFunctionBegin; 232*69ce434fSBarry Smith in->refcnt++; 233*69ce434fSBarry Smith ierr = PetscLayoutDestroy(out);CHKERRQ(ierr); 234*69ce434fSBarry Smith *out = in; 235*69ce434fSBarry Smith PetscFunctionReturn(0); 236*69ce434fSBarry Smith } 237*69ce434fSBarry Smith 238*69ce434fSBarry Smith #undef __FUNCT__ 239*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetISLocalToGlobalMapping" 240*69ce434fSBarry Smith /*@C 241*69ce434fSBarry Smith 242*69ce434fSBarry Smith PetscLayoutSetISLocalToGlobalMapping - sets a ISLocalGlobalMapping into a PetscLayout 243*69ce434fSBarry Smith 244*69ce434fSBarry Smith Collective on PetscLayout 245*69ce434fSBarry Smith 246*69ce434fSBarry Smith Input Parameter: 247*69ce434fSBarry Smith + in - input PetscLayout 248*69ce434fSBarry Smith - ltog - the local to global mapping 249*69ce434fSBarry Smith 250*69ce434fSBarry Smith 251*69ce434fSBarry Smith Level: developer 252*69ce434fSBarry Smith 253*69ce434fSBarry Smith Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout 254*69ce434fSBarry Smith 255*69ce434fSBarry Smith If the ltog location already contains a PetscLayout it is destroyed 256*69ce434fSBarry Smith 257*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate(), PetscLayoutSetLocalToGlobalMappingBlock() 258*69ce434fSBarry Smith 259*69ce434fSBarry Smith @*/ 260*69ce434fSBarry Smith PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout in,ISLocalToGlobalMapping ltog) 261*69ce434fSBarry Smith { 262*69ce434fSBarry Smith PetscErrorCode ierr; 263*69ce434fSBarry Smith 264*69ce434fSBarry Smith PetscFunctionBegin; 265*69ce434fSBarry Smith ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr); 266*69ce434fSBarry Smith ierr = ISLocalToGlobalMappingDestroy(&in->mapping);CHKERRQ(ierr); 267*69ce434fSBarry Smith 268*69ce434fSBarry Smith in->mapping = ltog; 269*69ce434fSBarry Smith PetscFunctionReturn(0); 270*69ce434fSBarry Smith } 271*69ce434fSBarry Smith 272*69ce434fSBarry Smith #undef __FUNCT__ 273*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetISLocalToGlobalMappingBlock" 274*69ce434fSBarry Smith /*@C 275*69ce434fSBarry Smith 276*69ce434fSBarry Smith PetscLayoutSetISLocalToGlobalMappingBlock - sets a ISLocalGlobalMapping into a PetscLayout 277*69ce434fSBarry Smith 278*69ce434fSBarry Smith Collective on PetscLayout 279*69ce434fSBarry Smith 280*69ce434fSBarry Smith Input Parameter: 281*69ce434fSBarry Smith + in - input PetscLayout 282*69ce434fSBarry Smith - ltog - the local to global block mapping 283*69ce434fSBarry Smith 284*69ce434fSBarry Smith 285*69ce434fSBarry Smith Level: developer 286*69ce434fSBarry Smith 287*69ce434fSBarry Smith Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout 288*69ce434fSBarry Smith 289*69ce434fSBarry Smith If the ltog location already contains a PetscLayout it is destroyed 290*69ce434fSBarry Smith 291*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate(), PetscLayoutSetLocalToGlobalMappingBlock() 292*69ce434fSBarry Smith 293*69ce434fSBarry Smith @*/ 294*69ce434fSBarry Smith PetscErrorCode PetscLayoutSetISLocalToGlobalMappingBlock(PetscLayout in,ISLocalToGlobalMapping ltog) 295*69ce434fSBarry Smith { 296*69ce434fSBarry Smith PetscErrorCode ierr; 297*69ce434fSBarry Smith 298*69ce434fSBarry Smith PetscFunctionBegin; 299*69ce434fSBarry Smith ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr); 300*69ce434fSBarry Smith ierr = ISLocalToGlobalMappingDestroy(&in->bmapping);CHKERRQ(ierr); 301*69ce434fSBarry Smith 302*69ce434fSBarry Smith in->bmapping = ltog; 303*69ce434fSBarry Smith PetscFunctionReturn(0); 304*69ce434fSBarry Smith } 305*69ce434fSBarry Smith 306*69ce434fSBarry Smith /*@C 307*69ce434fSBarry Smith PetscLayoutSetLocalSize - Sets the local size for a PetscLayout object. 308*69ce434fSBarry Smith 309*69ce434fSBarry Smith Collective on PetscLayout 310*69ce434fSBarry Smith 311*69ce434fSBarry Smith Input Parameters: 312*69ce434fSBarry Smith + map - pointer to the map 313*69ce434fSBarry Smith - n - the local size 314*69ce434fSBarry Smith 315*69ce434fSBarry Smith Level: developer 316*69ce434fSBarry Smith 317*69ce434fSBarry Smith Notes: 318*69ce434fSBarry Smith Call this after the call to PetscLayoutCreate() 319*69ce434fSBarry Smith 320*69ce434fSBarry Smith Fortran Notes: 321*69ce434fSBarry Smith Not available from Fortran 322*69ce434fSBarry Smith 323*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayoutSetUp() 324*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 325*69ce434fSBarry Smith 326*69ce434fSBarry Smith @*/ 327*69ce434fSBarry Smith #undef __FUNCT__ 328*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetLocalSize" 329*69ce434fSBarry Smith PetscErrorCode PetscLayoutSetLocalSize(PetscLayout map,PetscInt n) 330*69ce434fSBarry Smith { 331*69ce434fSBarry Smith PetscFunctionBegin; 332*69ce434fSBarry Smith if (map->bs > 1 && n % map->bs) SETERRQ2(map->comm,PETSC_ERR_ARG_INCOMP,"Local size %D not compatible with block size %D",n,map->bs); 333*69ce434fSBarry Smith map->n = n; 334*69ce434fSBarry Smith PetscFunctionReturn(0); 335*69ce434fSBarry Smith } 336*69ce434fSBarry Smith 337*69ce434fSBarry Smith /*@C 338*69ce434fSBarry Smith PetscLayoutGetLocalSize - Gets the local size for a PetscLayout object. 339*69ce434fSBarry Smith 340*69ce434fSBarry Smith Not Collective 341*69ce434fSBarry Smith 342*69ce434fSBarry Smith Input Parameters: 343*69ce434fSBarry Smith . map - pointer to the map 344*69ce434fSBarry Smith 345*69ce434fSBarry Smith Output Parameters: 346*69ce434fSBarry Smith . n - the local size 347*69ce434fSBarry Smith 348*69ce434fSBarry Smith Level: developer 349*69ce434fSBarry Smith 350*69ce434fSBarry Smith Notes: 351*69ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 352*69ce434fSBarry Smith 353*69ce434fSBarry Smith Fortran Notes: 354*69ce434fSBarry Smith Not available from Fortran 355*69ce434fSBarry Smith 356*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayoutSetUp() 357*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 358*69ce434fSBarry Smith 359*69ce434fSBarry Smith @*/ 360*69ce434fSBarry Smith #undef __FUNCT__ 361*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetLocalSize" 362*69ce434fSBarry Smith PetscErrorCode PetscLayoutGetLocalSize(PetscLayout map,PetscInt *n) 363*69ce434fSBarry Smith { 364*69ce434fSBarry Smith PetscFunctionBegin; 365*69ce434fSBarry Smith *n = map->n; 366*69ce434fSBarry Smith PetscFunctionReturn(0); 367*69ce434fSBarry Smith } 368*69ce434fSBarry Smith 369*69ce434fSBarry Smith /*@C 370*69ce434fSBarry Smith PetscLayoutSetSize - Sets the global size for a PetscLayout object. 371*69ce434fSBarry Smith 372*69ce434fSBarry Smith Logically Collective on PetscLayout 373*69ce434fSBarry Smith 374*69ce434fSBarry Smith Input Parameters: 375*69ce434fSBarry Smith + map - pointer to the map 376*69ce434fSBarry Smith - n - the global size 377*69ce434fSBarry Smith 378*69ce434fSBarry Smith Level: developer 379*69ce434fSBarry Smith 380*69ce434fSBarry Smith Notes: 381*69ce434fSBarry Smith Call this after the call to PetscLayoutCreate() 382*69ce434fSBarry Smith 383*69ce434fSBarry Smith Fortran Notes: 384*69ce434fSBarry Smith Not available from Fortran 385*69ce434fSBarry Smith 386*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 387*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 388*69ce434fSBarry Smith 389*69ce434fSBarry Smith @*/ 390*69ce434fSBarry Smith #undef __FUNCT__ 391*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetSize" 392*69ce434fSBarry Smith PetscErrorCode PetscLayoutSetSize(PetscLayout map,PetscInt n) 393*69ce434fSBarry Smith { 394*69ce434fSBarry Smith PetscFunctionBegin; 395*69ce434fSBarry Smith map->N = n; 396*69ce434fSBarry Smith PetscFunctionReturn(0); 397*69ce434fSBarry Smith } 398*69ce434fSBarry Smith 399*69ce434fSBarry Smith /*@C 400*69ce434fSBarry Smith PetscLayoutGetSize - Gets the global size for a PetscLayout object. 401*69ce434fSBarry Smith 402*69ce434fSBarry Smith Not Collective 403*69ce434fSBarry Smith 404*69ce434fSBarry Smith Input Parameters: 405*69ce434fSBarry Smith . map - pointer to the map 406*69ce434fSBarry Smith 407*69ce434fSBarry Smith Output Parameters: 408*69ce434fSBarry Smith . n - the global size 409*69ce434fSBarry Smith 410*69ce434fSBarry Smith Level: developer 411*69ce434fSBarry Smith 412*69ce434fSBarry Smith Notes: 413*69ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 414*69ce434fSBarry Smith 415*69ce434fSBarry Smith Fortran Notes: 416*69ce434fSBarry Smith Not available from Fortran 417*69ce434fSBarry Smith 418*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), PetscLayoutSetUp() 419*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 420*69ce434fSBarry Smith 421*69ce434fSBarry Smith @*/ 422*69ce434fSBarry Smith #undef __FUNCT__ 423*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetSize" 424*69ce434fSBarry Smith PetscErrorCode PetscLayoutGetSize(PetscLayout map,PetscInt *n) 425*69ce434fSBarry Smith { 426*69ce434fSBarry Smith PetscFunctionBegin; 427*69ce434fSBarry Smith *n = map->N; 428*69ce434fSBarry Smith PetscFunctionReturn(0); 429*69ce434fSBarry Smith } 430*69ce434fSBarry Smith 431*69ce434fSBarry Smith /*@C 432*69ce434fSBarry Smith PetscLayoutSetBlockSize - Sets the block size for a PetscLayout object. 433*69ce434fSBarry Smith 434*69ce434fSBarry Smith Logically Collective on PetscLayout 435*69ce434fSBarry Smith 436*69ce434fSBarry Smith Input Parameters: 437*69ce434fSBarry Smith + map - pointer to the map 438*69ce434fSBarry Smith - bs - the size 439*69ce434fSBarry Smith 440*69ce434fSBarry Smith Level: developer 441*69ce434fSBarry Smith 442*69ce434fSBarry Smith Notes: 443*69ce434fSBarry Smith Call this after the call to PetscLayoutCreate() 444*69ce434fSBarry Smith 445*69ce434fSBarry Smith Fortran Notes: 446*69ce434fSBarry Smith Not available from Fortran 447*69ce434fSBarry Smith 448*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutGetBlockSize(), 449*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 450*69ce434fSBarry Smith 451*69ce434fSBarry Smith @*/ 452*69ce434fSBarry Smith #undef __FUNCT__ 453*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetBlockSize" 454*69ce434fSBarry Smith PetscErrorCode PetscLayoutSetBlockSize(PetscLayout map,PetscInt bs) 455*69ce434fSBarry Smith { 456*69ce434fSBarry Smith PetscFunctionBegin; 457*69ce434fSBarry Smith if (map->n > 0 && map->n % bs) SETERRQ2(map->comm,PETSC_ERR_ARG_INCOMP,"Local size %D not compatible with block size %D",map->n,bs); 458*69ce434fSBarry Smith if (map->bs > 0 && map->bs != bs) SETERRQ2(map->comm,PETSC_ERR_ARG_INCOMP,"Cannot change block size %D to %D",map->bs,bs); 459*69ce434fSBarry Smith map->bs = bs; 460*69ce434fSBarry Smith PetscFunctionReturn(0); 461*69ce434fSBarry Smith } 462*69ce434fSBarry Smith 463*69ce434fSBarry Smith /*@C 464*69ce434fSBarry Smith PetscLayoutGetBlockSize - Gets the block size for a PetscLayout object. 465*69ce434fSBarry Smith 466*69ce434fSBarry Smith Not Collective 467*69ce434fSBarry Smith 468*69ce434fSBarry Smith Input Parameters: 469*69ce434fSBarry Smith . map - pointer to the map 470*69ce434fSBarry Smith 471*69ce434fSBarry Smith Output Parameters: 472*69ce434fSBarry Smith . bs - the size 473*69ce434fSBarry Smith 474*69ce434fSBarry Smith Level: developer 475*69ce434fSBarry Smith 476*69ce434fSBarry Smith Notes: 477*69ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 478*69ce434fSBarry Smith 479*69ce434fSBarry Smith Fortran Notes: 480*69ce434fSBarry Smith Not available from Fortran 481*69ce434fSBarry Smith 482*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), PetscLayoutSetUp() 483*69ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetSize() 484*69ce434fSBarry Smith 485*69ce434fSBarry Smith @*/ 486*69ce434fSBarry Smith #undef __FUNCT__ 487*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetBlockSize" 488*69ce434fSBarry Smith PetscErrorCode PetscLayoutGetBlockSize(PetscLayout map,PetscInt *bs) 489*69ce434fSBarry Smith { 490*69ce434fSBarry Smith PetscFunctionBegin; 491*69ce434fSBarry Smith *bs = map->bs; 492*69ce434fSBarry Smith PetscFunctionReturn(0); 493*69ce434fSBarry Smith } 494*69ce434fSBarry Smith 495*69ce434fSBarry Smith 496*69ce434fSBarry Smith /*@C 497*69ce434fSBarry Smith PetscLayoutGetRange - gets the range of values owned by this process 498*69ce434fSBarry Smith 499*69ce434fSBarry Smith Not Collective 500*69ce434fSBarry Smith 501*69ce434fSBarry Smith Input Parameters: 502*69ce434fSBarry Smith . map - pointer to the map 503*69ce434fSBarry Smith 504*69ce434fSBarry Smith Output Parameters: 505*69ce434fSBarry Smith + rstart - first index owned by this process 506*69ce434fSBarry Smith - rend - one more than the last index owned by this process 507*69ce434fSBarry Smith 508*69ce434fSBarry Smith Level: developer 509*69ce434fSBarry Smith 510*69ce434fSBarry Smith Notes: 511*69ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 512*69ce434fSBarry Smith 513*69ce434fSBarry Smith Fortran Notes: 514*69ce434fSBarry Smith Not available from Fortran 515*69ce434fSBarry Smith 516*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), 517*69ce434fSBarry Smith PetscLayoutGetSize(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 518*69ce434fSBarry Smith 519*69ce434fSBarry Smith @*/ 520*69ce434fSBarry Smith #undef __FUNCT__ 521*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetRange" 522*69ce434fSBarry Smith PetscErrorCode PetscLayoutGetRange(PetscLayout map,PetscInt *rstart,PetscInt *rend) 523*69ce434fSBarry Smith { 524*69ce434fSBarry Smith PetscFunctionBegin; 525*69ce434fSBarry Smith if (rstart) *rstart = map->rstart; 526*69ce434fSBarry Smith if (rend) *rend = map->rend; 527*69ce434fSBarry Smith PetscFunctionReturn(0); 528*69ce434fSBarry Smith } 529*69ce434fSBarry Smith 530*69ce434fSBarry Smith /*@C 531*69ce434fSBarry Smith PetscLayoutGetRanges - gets the range of values owned by all processes 532*69ce434fSBarry Smith 533*69ce434fSBarry Smith Not Collective 534*69ce434fSBarry Smith 535*69ce434fSBarry Smith Input Parameters: 536*69ce434fSBarry Smith . map - pointer to the map 537*69ce434fSBarry Smith 538*69ce434fSBarry Smith Output Parameters: 539*69ce434fSBarry Smith . range - start of each processors range of indices (the final entry is one more then the 540*69ce434fSBarry Smith last index on the last process) 541*69ce434fSBarry Smith 542*69ce434fSBarry Smith Level: developer 543*69ce434fSBarry Smith 544*69ce434fSBarry Smith Notes: 545*69ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 546*69ce434fSBarry Smith 547*69ce434fSBarry Smith Fortran Notes: 548*69ce434fSBarry Smith Not available from Fortran 549*69ce434fSBarry Smith 550*69ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), 551*69ce434fSBarry Smith PetscLayoutGetSize(), PetscLayoutGetRange(), PetscLayoutSetBlockSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 552*69ce434fSBarry Smith 553*69ce434fSBarry Smith @*/ 554*69ce434fSBarry Smith #undef __FUNCT__ 555*69ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetRanges" 556*69ce434fSBarry Smith PetscErrorCode PetscLayoutGetRanges(PetscLayout map,const PetscInt *range[]) 557*69ce434fSBarry Smith { 558*69ce434fSBarry Smith PetscFunctionBegin; 559*69ce434fSBarry Smith *range = map->range; 560*69ce434fSBarry Smith PetscFunctionReturn(0); 561*69ce434fSBarry Smith } 562*69ce434fSBarry Smith 563*69ce434fSBarry Smith #undef __FUNCT__ 564*69ce434fSBarry Smith #define __FUNCT__ "PetscSFSetGraphLayout" 565*69ce434fSBarry Smith /*@C 566*69ce434fSBarry Smith PetscSFSetGraphLayout - Set a parallel star forest via global indices and a PetscLayout 567*69ce434fSBarry Smith 568*69ce434fSBarry Smith Collective 569*69ce434fSBarry Smith 570*69ce434fSBarry Smith Input Arguments: 571*69ce434fSBarry Smith + sf - star forest 572*69ce434fSBarry Smith . layout - PetscLayout defining the global space 573*69ce434fSBarry Smith . nleaves - number of leaf vertices on the current process, each of these references a root on any process 574*69ce434fSBarry Smith . ilocal - locations of leaves in leafdata buffers, pass NULL for contiguous storage 575*69ce434fSBarry Smith - iremote - remote locations of root vertices for each leaf on the current process 576*69ce434fSBarry Smith 577*69ce434fSBarry Smith Level: intermediate 578*69ce434fSBarry Smith 579*69ce434fSBarry Smith .seealso: PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph() 580*69ce434fSBarry Smith @*/ 581*69ce434fSBarry Smith PetscErrorCode PetscSFSetGraphLayout(PetscSF sf,PetscLayout layout,PetscInt nleaves,const PetscInt *ilocal,PetscCopyMode localmode,const PetscInt *iremote) 582*69ce434fSBarry Smith { 583*69ce434fSBarry Smith PetscErrorCode ierr; 584*69ce434fSBarry Smith PetscInt i,nroots; 585*69ce434fSBarry Smith PetscSFNode *remote; 586*69ce434fSBarry Smith 587*69ce434fSBarry Smith PetscFunctionBegin; 588*69ce434fSBarry Smith ierr = PetscLayoutGetLocalSize(layout,&nroots);CHKERRQ(ierr); 589*69ce434fSBarry Smith ierr = PetscMalloc(nleaves*sizeof(PetscSFNode),&remote);CHKERRQ(ierr); 590*69ce434fSBarry Smith for (i=0; i<nleaves; i++) { 591*69ce434fSBarry Smith PetscInt owner = -1; 592*69ce434fSBarry Smith ierr = PetscLayoutFindOwner(layout,iremote[i],&owner);CHKERRQ(ierr); 593*69ce434fSBarry Smith remote[i].rank = owner; 594*69ce434fSBarry Smith remote[i].index = iremote[i] - layout->range[owner]; 595*69ce434fSBarry Smith } 596*69ce434fSBarry Smith ierr = PetscSFSetGraph(sf,nroots,nleaves,ilocal,localmode,remote,PETSC_OWN_POINTER);CHKERRQ(ierr); 597*69ce434fSBarry Smith PetscFunctionReturn(0); 598*69ce434fSBarry Smith } 599*69ce434fSBarry Smith 600