169ce434fSBarry Smith 269ce434fSBarry Smith /* 369ce434fSBarry Smith This file contains routines for basic map object implementation. 469ce434fSBarry Smith */ 569ce434fSBarry Smith 6c3002683SMatthew G. Knepley #include <petscis.h> /*I "petscis.h" I*/ 70c312b8eSJed Brown #include <petscsf.h> 85c25fcd7SBarry Smith 969ce434fSBarry Smith #undef __FUNCT__ 1069ce434fSBarry Smith #define __FUNCT__ "PetscLayoutCreate" 11c3002683SMatthew G. Knepley /*@ 1269ce434fSBarry Smith PetscLayoutCreate - Allocates PetscLayout space and sets the map contents to the default. 1369ce434fSBarry Smith 1469ce434fSBarry Smith Collective on MPI_Comm 1569ce434fSBarry Smith 1669ce434fSBarry Smith Input Parameters: 1769ce434fSBarry Smith + comm - the MPI communicator 1869ce434fSBarry Smith - map - pointer to the map 1969ce434fSBarry Smith 20456fcb79SJed Brown Level: advanced 2169ce434fSBarry Smith 22456fcb79SJed Brown Notes: 23456fcb79SJed Brown Typical calling sequence 24456fcb79SJed Brown .vb 2569ce434fSBarry Smith PetscLayoutCreate(MPI_Comm,PetscLayout *); 2669ce434fSBarry Smith PetscLayoutSetBlockSize(PetscLayout,1); 27456fcb79SJed Brown PetscLayoutSetSize(PetscLayout,N) // or PetscLayoutSetLocalSize(PetscLayout,n); 2869ce434fSBarry Smith PetscLayoutSetUp(PetscLayout); 29456fcb79SJed Brown .ve 3069ce434fSBarry Smith Optionally use any of the following: 31456fcb79SJed Brown 32456fcb79SJed Brown + PetscLayoutGetSize(PetscLayout,PetscInt *); 33456fcb79SJed Brown . PetscLayoutGetLocalSize(PetscLayout,PetscInt *); 34456fcb79SJed Brown . PetscLayoutGetRange(PetscLayout,PetscInt *rstart,PetscInt *rend); 35456fcb79SJed Brown . PetscLayoutGetRanges(PetscLayout,const PetscInt *range[]); 36456fcb79SJed Brown - PetscLayoutDestroy(PetscLayout*); 3769ce434fSBarry Smith 3869ce434fSBarry Smith The PetscLayout object and methods are intended to be used in the PETSc Vec and Mat implementions; it is often not needed in 3969ce434fSBarry Smith user codes unless you really gain something in their use. 4069ce434fSBarry Smith 4169ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutDestroy(), 4269ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutSetUp() 4369ce434fSBarry Smith 4469ce434fSBarry Smith @*/ 4569ce434fSBarry Smith PetscErrorCode PetscLayoutCreate(MPI_Comm comm,PetscLayout *map) 4669ce434fSBarry Smith { 4769ce434fSBarry Smith PetscErrorCode ierr; 4869ce434fSBarry Smith 4969ce434fSBarry Smith PetscFunctionBegin; 50b00a9115SJed Brown ierr = PetscNew(map);CHKERRQ(ierr); 5169ce434fSBarry Smith 5269ce434fSBarry Smith (*map)->comm = comm; 5369ce434fSBarry Smith (*map)->bs = -1; 5469ce434fSBarry Smith (*map)->n = -1; 5569ce434fSBarry Smith (*map)->N = -1; 5669ce434fSBarry Smith (*map)->range = 0; 5769ce434fSBarry Smith (*map)->rstart = 0; 5869ce434fSBarry Smith (*map)->rend = 0; 5969ce434fSBarry Smith PetscFunctionReturn(0); 6069ce434fSBarry Smith } 6169ce434fSBarry Smith 62c3002683SMatthew G. Knepley #undef __FUNCT__ 63c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutDestroy" 64c3002683SMatthew G. Knepley /*@ 6569ce434fSBarry Smith PetscLayoutDestroy - Frees a map object and frees its range if that exists. 6669ce434fSBarry Smith 6769ce434fSBarry Smith Collective on MPI_Comm 6869ce434fSBarry Smith 6969ce434fSBarry Smith Input Parameters: 7069ce434fSBarry Smith . map - the PetscLayout 7169ce434fSBarry Smith 7269ce434fSBarry Smith Level: developer 7369ce434fSBarry Smith 74c3002683SMatthew G. Knepley Note: 7569ce434fSBarry Smith The PetscLayout object and methods are intended to be used in the PETSc Vec and Mat implementions; it is 7669ce434fSBarry Smith recommended they not be used in user codes unless you really gain something in their use. 7769ce434fSBarry Smith 7869ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutCreate(), 7969ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutSetUp() 8069ce434fSBarry Smith 8169ce434fSBarry Smith @*/ 8269ce434fSBarry Smith PetscErrorCode PetscLayoutDestroy(PetscLayout *map) 8369ce434fSBarry Smith { 8469ce434fSBarry Smith PetscErrorCode ierr; 8569ce434fSBarry Smith 8669ce434fSBarry Smith PetscFunctionBegin; 8769ce434fSBarry Smith if (!*map) PetscFunctionReturn(0); 8869ce434fSBarry Smith if (!(*map)->refcnt--) { 8969ce434fSBarry Smith ierr = PetscFree((*map)->range);CHKERRQ(ierr); 9069ce434fSBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*map)->mapping);CHKERRQ(ierr); 9169ce434fSBarry Smith ierr = PetscFree((*map));CHKERRQ(ierr); 9269ce434fSBarry Smith } 9369ce434fSBarry Smith *map = NULL; 9469ce434fSBarry Smith PetscFunctionReturn(0); 9569ce434fSBarry Smith } 9669ce434fSBarry Smith 97c3002683SMatthew G. Knepley #undef __FUNCT__ 98c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutSetUp" 99c3002683SMatthew G. Knepley /*@ 10069ce434fSBarry Smith PetscLayoutSetUp - given a map where you have set either the global or local 10169ce434fSBarry Smith size sets up the map so that it may be used. 10269ce434fSBarry Smith 10369ce434fSBarry Smith Collective on MPI_Comm 10469ce434fSBarry Smith 10569ce434fSBarry Smith Input Parameters: 10669ce434fSBarry Smith . map - pointer to the map 10769ce434fSBarry Smith 10869ce434fSBarry Smith Level: developer 10969ce434fSBarry Smith 11069ce434fSBarry Smith Notes: Typical calling sequence 111c3002683SMatthew G. Knepley $ PetscLayoutCreate(MPI_Comm,PetscLayout *); 112c3002683SMatthew G. Knepley $ PetscLayoutSetBlockSize(PetscLayout,1); 113c3002683SMatthew G. Knepley $ PetscLayoutSetSize(PetscLayout,n) or PetscLayoutSetLocalSize(PetscLayout,N); or both 114c3002683SMatthew G. Knepley $ PetscLayoutSetUp(PetscLayout); 115c3002683SMatthew G. Knepley $ PetscLayoutGetSize(PetscLayout,PetscInt *); 11669ce434fSBarry Smith 11769ce434fSBarry Smith 11869ce434fSBarry Smith If the local size, global size are already set and range exists then this does nothing. 11969ce434fSBarry Smith 12069ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutDestroy(), 12169ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutCreate() 12269ce434fSBarry Smith @*/ 12369ce434fSBarry Smith PetscErrorCode PetscLayoutSetUp(PetscLayout map) 12469ce434fSBarry Smith { 12569ce434fSBarry Smith PetscMPIInt rank,size; 12669ce434fSBarry Smith PetscInt p; 12769ce434fSBarry Smith PetscErrorCode ierr; 12869ce434fSBarry Smith 12969ce434fSBarry Smith PetscFunctionBegin; 13069ce434fSBarry Smith if ((map->n >= 0) && (map->N >= 0) && (map->range)) PetscFunctionReturn(0); 13169ce434fSBarry Smith 132*b146b01cSBarry Smith if (map->n > 0 && map->bs > 1) { 133*b146b01cSBarry Smith if (map->n % map->bs) { 134*b146b01cSBarry Smith SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Local matrix size %D must be divisible by blocksize %D",map->n,map->bs); 135*b146b01cSBarry Smith } 136*b146b01cSBarry Smith } 137*b146b01cSBarry Smith if (map->N > 0 && map->bs > 1) { 138*b146b01cSBarry Smith if (map->N % map->bs) { 139*b146b01cSBarry Smith SETERRQ2(map->comm,PETSC_ERR_PLIB,"Global matrix size %D must be divisible by blocksize %D",map->N,map->bs); 140*b146b01cSBarry Smith } 141*b146b01cSBarry Smith } 142*b146b01cSBarry Smith 14369ce434fSBarry Smith ierr = MPI_Comm_size(map->comm, &size);CHKERRQ(ierr); 14469ce434fSBarry Smith ierr = MPI_Comm_rank(map->comm, &rank);CHKERRQ(ierr); 14533d57670SJed Brown if (map->n > 0) map->n = map->n/PetscAbs(map->bs); 14633d57670SJed Brown if (map->N > 0) map->N = map->N/PetscAbs(map->bs); 14769ce434fSBarry Smith ierr = PetscSplitOwnership(map->comm,&map->n,&map->N);CHKERRQ(ierr); 14833d57670SJed Brown map->n = map->n*PetscAbs(map->bs); 14933d57670SJed Brown map->N = map->N*PetscAbs(map->bs); 15069ce434fSBarry Smith if (!map->range) { 151854ce69bSBarry Smith ierr = PetscMalloc1(size+1, &map->range);CHKERRQ(ierr); 15269ce434fSBarry Smith } 15369ce434fSBarry Smith ierr = MPI_Allgather(&map->n, 1, MPIU_INT, map->range+1, 1, MPIU_INT, map->comm);CHKERRQ(ierr); 15469ce434fSBarry Smith 15569ce434fSBarry Smith map->range[0] = 0; 15669ce434fSBarry Smith for (p = 2; p <= size; p++) map->range[p] += map->range[p-1]; 15769ce434fSBarry Smith 15869ce434fSBarry Smith map->rstart = map->range[rank]; 15969ce434fSBarry Smith map->rend = map->range[rank+1]; 16069ce434fSBarry Smith PetscFunctionReturn(0); 16169ce434fSBarry Smith } 16269ce434fSBarry Smith 16369ce434fSBarry Smith #undef __FUNCT__ 16469ce434fSBarry Smith #define __FUNCT__ "PetscLayoutDuplicate" 165c3002683SMatthew G. Knepley /*@ 16669ce434fSBarry Smith PetscLayoutDuplicate - creates a new PetscLayout with the same information as a given one. If the PetscLayout already exists it is destroyed first. 16769ce434fSBarry Smith 16869ce434fSBarry Smith Collective on PetscLayout 16969ce434fSBarry Smith 17069ce434fSBarry Smith Input Parameter: 17169ce434fSBarry Smith . in - input PetscLayout to be duplicated 17269ce434fSBarry Smith 17369ce434fSBarry Smith Output Parameter: 17469ce434fSBarry Smith . out - the copy 17569ce434fSBarry Smith 17669ce434fSBarry Smith Level: developer 17769ce434fSBarry Smith 17869ce434fSBarry Smith Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout 17969ce434fSBarry Smith 18069ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutReference() 18169ce434fSBarry Smith @*/ 18269ce434fSBarry Smith PetscErrorCode PetscLayoutDuplicate(PetscLayout in,PetscLayout *out) 18369ce434fSBarry Smith { 18469ce434fSBarry Smith PetscMPIInt size; 18569ce434fSBarry Smith PetscErrorCode ierr; 18669ce434fSBarry Smith MPI_Comm comm = in->comm; 18769ce434fSBarry Smith 18869ce434fSBarry Smith PetscFunctionBegin; 18969ce434fSBarry Smith ierr = PetscLayoutDestroy(out);CHKERRQ(ierr); 19069ce434fSBarry Smith ierr = PetscLayoutCreate(comm,out);CHKERRQ(ierr); 19169ce434fSBarry Smith ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 19269ce434fSBarry Smith ierr = PetscMemcpy(*out,in,sizeof(struct _n_PetscLayout));CHKERRQ(ierr); 193854ce69bSBarry Smith ierr = PetscMalloc1(size+1,&(*out)->range);CHKERRQ(ierr); 19469ce434fSBarry Smith ierr = PetscMemcpy((*out)->range,in->range,(size+1)*sizeof(PetscInt));CHKERRQ(ierr); 19569ce434fSBarry Smith 19669ce434fSBarry Smith (*out)->refcnt = 0; 19769ce434fSBarry Smith PetscFunctionReturn(0); 19869ce434fSBarry Smith } 19969ce434fSBarry Smith 20069ce434fSBarry Smith #undef __FUNCT__ 20169ce434fSBarry Smith #define __FUNCT__ "PetscLayoutReference" 202c3002683SMatthew G. Knepley /*@ 20369ce434fSBarry Smith PetscLayoutReference - Causes a PETSc Vec or Mat to share a PetscLayout with one that already exists. Used by Vec/MatDuplicate_XXX() 20469ce434fSBarry Smith 20569ce434fSBarry Smith Collective on PetscLayout 20669ce434fSBarry Smith 20769ce434fSBarry Smith Input Parameter: 20869ce434fSBarry Smith . in - input PetscLayout to be copied 20969ce434fSBarry Smith 21069ce434fSBarry Smith Output Parameter: 21169ce434fSBarry Smith . out - the reference location 21269ce434fSBarry Smith 21369ce434fSBarry Smith Level: developer 21469ce434fSBarry Smith 21569ce434fSBarry Smith Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout 21669ce434fSBarry Smith 21769ce434fSBarry Smith If the out location already contains a PetscLayout it is destroyed 21869ce434fSBarry Smith 21969ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate() 22069ce434fSBarry Smith @*/ 22169ce434fSBarry Smith PetscErrorCode PetscLayoutReference(PetscLayout in,PetscLayout *out) 22269ce434fSBarry Smith { 22369ce434fSBarry Smith PetscErrorCode ierr; 22469ce434fSBarry Smith 22569ce434fSBarry Smith PetscFunctionBegin; 22669ce434fSBarry Smith in->refcnt++; 22769ce434fSBarry Smith ierr = PetscLayoutDestroy(out);CHKERRQ(ierr); 22869ce434fSBarry Smith *out = in; 22969ce434fSBarry Smith PetscFunctionReturn(0); 23069ce434fSBarry Smith } 23169ce434fSBarry Smith 23269ce434fSBarry Smith #undef __FUNCT__ 23369ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetISLocalToGlobalMapping" 234c3002683SMatthew G. Knepley /*@ 23569ce434fSBarry Smith PetscLayoutSetISLocalToGlobalMapping - sets a ISLocalGlobalMapping into a PetscLayout 23669ce434fSBarry Smith 23769ce434fSBarry Smith Collective on PetscLayout 23869ce434fSBarry Smith 23969ce434fSBarry Smith Input Parameter: 24069ce434fSBarry Smith + in - input PetscLayout 24169ce434fSBarry Smith - ltog - the local to global mapping 24269ce434fSBarry Smith 24369ce434fSBarry Smith 24469ce434fSBarry Smith Level: developer 24569ce434fSBarry Smith 24669ce434fSBarry Smith Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout 24769ce434fSBarry Smith 24869ce434fSBarry Smith If the ltog location already contains a PetscLayout it is destroyed 24969ce434fSBarry Smith 250a188d78dSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate() 25169ce434fSBarry Smith @*/ 25269ce434fSBarry Smith PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout in,ISLocalToGlobalMapping ltog) 25369ce434fSBarry Smith { 25469ce434fSBarry Smith PetscErrorCode ierr; 25545b6f7e9SBarry Smith PetscInt bs; 25669ce434fSBarry Smith 25769ce434fSBarry Smith PetscFunctionBegin; 25845b6f7e9SBarry Smith ierr = ISLocalToGlobalMappingGetBlockSize(ltog,&bs);CHKERRQ(ierr); 25945b6f7e9SBarry Smith if (in->bs > 0 && in->bs != bs) SETERRQ2(in->comm,PETSC_ERR_PLIB,"Blocksize of layout %D must match that of mapping %D",in->bs,bs); 26069ce434fSBarry Smith ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr); 26169ce434fSBarry Smith ierr = ISLocalToGlobalMappingDestroy(&in->mapping);CHKERRQ(ierr); 26269ce434fSBarry Smith in->mapping = ltog; 26369ce434fSBarry Smith PetscFunctionReturn(0); 26469ce434fSBarry Smith } 26569ce434fSBarry Smith 266c3002683SMatthew G. Knepley #undef __FUNCT__ 267c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutSetLocalSize" 268c3002683SMatthew G. Knepley /*@ 26969ce434fSBarry Smith PetscLayoutSetLocalSize - Sets the local size for a PetscLayout object. 27069ce434fSBarry Smith 27169ce434fSBarry Smith Collective on PetscLayout 27269ce434fSBarry Smith 27369ce434fSBarry Smith Input Parameters: 27469ce434fSBarry Smith + map - pointer to the map 27569ce434fSBarry Smith - n - the local size 27669ce434fSBarry Smith 27769ce434fSBarry Smith Level: developer 27869ce434fSBarry Smith 27969ce434fSBarry Smith Notes: 28069ce434fSBarry Smith Call this after the call to PetscLayoutCreate() 28169ce434fSBarry Smith 28269ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayoutSetUp() 28369ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 28469ce434fSBarry Smith @*/ 28569ce434fSBarry Smith PetscErrorCode PetscLayoutSetLocalSize(PetscLayout map,PetscInt n) 28669ce434fSBarry Smith { 28769ce434fSBarry Smith PetscFunctionBegin; 28869ce434fSBarry 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); 28969ce434fSBarry Smith map->n = n; 29069ce434fSBarry Smith PetscFunctionReturn(0); 29169ce434fSBarry Smith } 29269ce434fSBarry Smith 29369ce434fSBarry Smith /*@C 29469ce434fSBarry Smith PetscLayoutGetLocalSize - Gets the local size for a PetscLayout object. 29569ce434fSBarry Smith 29669ce434fSBarry Smith Not Collective 29769ce434fSBarry Smith 29869ce434fSBarry Smith Input Parameters: 29969ce434fSBarry Smith . map - pointer to the map 30069ce434fSBarry Smith 30169ce434fSBarry Smith Output Parameters: 30269ce434fSBarry Smith . n - the local size 30369ce434fSBarry Smith 30469ce434fSBarry Smith Level: developer 30569ce434fSBarry Smith 30669ce434fSBarry Smith Notes: 30769ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 30869ce434fSBarry Smith 30969ce434fSBarry Smith Fortran Notes: 31069ce434fSBarry Smith Not available from Fortran 31169ce434fSBarry Smith 31269ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayoutSetUp() 31369ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 31469ce434fSBarry Smith 31569ce434fSBarry Smith @*/ 31669ce434fSBarry Smith #undef __FUNCT__ 31769ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetLocalSize" 31869ce434fSBarry Smith PetscErrorCode PetscLayoutGetLocalSize(PetscLayout map,PetscInt *n) 31969ce434fSBarry Smith { 32069ce434fSBarry Smith PetscFunctionBegin; 32169ce434fSBarry Smith *n = map->n; 32269ce434fSBarry Smith PetscFunctionReturn(0); 32369ce434fSBarry Smith } 32469ce434fSBarry Smith 325c3002683SMatthew G. Knepley #undef __FUNCT__ 326c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutSetSize" 327c3002683SMatthew G. Knepley /*@ 32869ce434fSBarry Smith PetscLayoutSetSize - Sets the global size for a PetscLayout object. 32969ce434fSBarry Smith 33069ce434fSBarry Smith Logically Collective on PetscLayout 33169ce434fSBarry Smith 33269ce434fSBarry Smith Input Parameters: 33369ce434fSBarry Smith + map - pointer to the map 33469ce434fSBarry Smith - n - the global size 33569ce434fSBarry Smith 33669ce434fSBarry Smith Level: developer 33769ce434fSBarry Smith 33869ce434fSBarry Smith Notes: 33969ce434fSBarry Smith Call this after the call to PetscLayoutCreate() 34069ce434fSBarry Smith 34169ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 34269ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 34369ce434fSBarry Smith @*/ 34469ce434fSBarry Smith PetscErrorCode PetscLayoutSetSize(PetscLayout map,PetscInt n) 34569ce434fSBarry Smith { 34669ce434fSBarry Smith PetscFunctionBegin; 34769ce434fSBarry Smith map->N = n; 34869ce434fSBarry Smith PetscFunctionReturn(0); 34969ce434fSBarry Smith } 35069ce434fSBarry Smith 351c3002683SMatthew G. Knepley #undef __FUNCT__ 352c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutGetSize" 353c3002683SMatthew G. Knepley /*@ 35469ce434fSBarry Smith PetscLayoutGetSize - Gets the global size for a PetscLayout object. 35569ce434fSBarry Smith 35669ce434fSBarry Smith Not Collective 35769ce434fSBarry Smith 35869ce434fSBarry Smith Input Parameters: 35969ce434fSBarry Smith . map - pointer to the map 36069ce434fSBarry Smith 36169ce434fSBarry Smith Output Parameters: 36269ce434fSBarry Smith . n - the global size 36369ce434fSBarry Smith 36469ce434fSBarry Smith Level: developer 36569ce434fSBarry Smith 36669ce434fSBarry Smith Notes: 36769ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 36869ce434fSBarry Smith 36969ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), PetscLayoutSetUp() 37069ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize() 37169ce434fSBarry Smith @*/ 37269ce434fSBarry Smith PetscErrorCode PetscLayoutGetSize(PetscLayout map,PetscInt *n) 37369ce434fSBarry Smith { 37469ce434fSBarry Smith PetscFunctionBegin; 37569ce434fSBarry Smith *n = map->N; 37669ce434fSBarry Smith PetscFunctionReturn(0); 37769ce434fSBarry Smith } 37869ce434fSBarry Smith 379c3002683SMatthew G. Knepley #undef __FUNCT__ 380c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutSetBlockSize" 381c3002683SMatthew G. Knepley /*@ 38269ce434fSBarry Smith PetscLayoutSetBlockSize - Sets the block size for a PetscLayout object. 38369ce434fSBarry Smith 38469ce434fSBarry Smith Logically Collective on PetscLayout 38569ce434fSBarry Smith 38669ce434fSBarry Smith Input Parameters: 38769ce434fSBarry Smith + map - pointer to the map 38869ce434fSBarry Smith - bs - the size 38969ce434fSBarry Smith 39069ce434fSBarry Smith Level: developer 39169ce434fSBarry Smith 39269ce434fSBarry Smith Notes: 39369ce434fSBarry Smith Call this after the call to PetscLayoutCreate() 39469ce434fSBarry Smith 39569ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutGetBlockSize(), 39669ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 39769ce434fSBarry Smith @*/ 39869ce434fSBarry Smith PetscErrorCode PetscLayoutSetBlockSize(PetscLayout map,PetscInt bs) 39969ce434fSBarry Smith { 40069ce434fSBarry Smith PetscFunctionBegin; 40169bbac97SJed Brown if (bs < 0) PetscFunctionReturn(0); 40269ce434fSBarry 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); 4033059b6faSBarry Smith if (map->range && map->bs > 0 && map->bs != bs) SETERRQ2(map->comm,PETSC_ERR_ARG_INCOMP,"Cannot change block size %D to %D",map->bs,bs); 404565245c5SBarry Smith if (map->mapping) { 405565245c5SBarry Smith PetscInt lbs; 406565245c5SBarry Smith PetscErrorCode ierr; 407565245c5SBarry Smith 408565245c5SBarry Smith ierr = ISLocalToGlobalMappingGetBlockSize(map->mapping,&lbs);CHKERRQ(ierr); 409565245c5SBarry Smith if (lbs != bs) SETERRQ2(map->comm,PETSC_ERR_PLIB,"Blocksize of localtoglobalmapping %D must match that of layout %D",lbs,bs); 410565245c5SBarry Smith } 41169ce434fSBarry Smith map->bs = bs; 41269ce434fSBarry Smith PetscFunctionReturn(0); 41369ce434fSBarry Smith } 41469ce434fSBarry Smith 415c3002683SMatthew G. Knepley #undef __FUNCT__ 416c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutGetBlockSize" 417c3002683SMatthew G. Knepley /*@ 41869ce434fSBarry Smith PetscLayoutGetBlockSize - Gets the block size for a PetscLayout object. 41969ce434fSBarry Smith 42069ce434fSBarry Smith Not Collective 42169ce434fSBarry Smith 42269ce434fSBarry Smith Input Parameters: 42369ce434fSBarry Smith . map - pointer to the map 42469ce434fSBarry Smith 42569ce434fSBarry Smith Output Parameters: 42669ce434fSBarry Smith . bs - the size 42769ce434fSBarry Smith 42869ce434fSBarry Smith Level: developer 42969ce434fSBarry Smith 43069ce434fSBarry Smith Notes: 43169ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 43269ce434fSBarry Smith 43369ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), PetscLayoutSetUp() 43469ce434fSBarry Smith PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetSize() 43569ce434fSBarry Smith @*/ 43669ce434fSBarry Smith PetscErrorCode PetscLayoutGetBlockSize(PetscLayout map,PetscInt *bs) 43769ce434fSBarry Smith { 43869ce434fSBarry Smith PetscFunctionBegin; 43933d57670SJed Brown *bs = PetscAbs(map->bs); 44069ce434fSBarry Smith PetscFunctionReturn(0); 44169ce434fSBarry Smith } 44269ce434fSBarry Smith 443c3002683SMatthew G. Knepley #undef __FUNCT__ 444c3002683SMatthew G. Knepley #define __FUNCT__ "PetscLayoutGetRange" 445c3002683SMatthew G. Knepley /*@ 44669ce434fSBarry Smith PetscLayoutGetRange - gets the range of values owned by this process 44769ce434fSBarry Smith 44869ce434fSBarry Smith Not Collective 44969ce434fSBarry Smith 45069ce434fSBarry Smith Input Parameters: 45169ce434fSBarry Smith . map - pointer to the map 45269ce434fSBarry Smith 45369ce434fSBarry Smith Output Parameters: 45469ce434fSBarry Smith + rstart - first index owned by this process 45569ce434fSBarry Smith - rend - one more than the last index owned by this process 45669ce434fSBarry Smith 45769ce434fSBarry Smith Level: developer 45869ce434fSBarry Smith 45969ce434fSBarry Smith Notes: 46069ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 46169ce434fSBarry Smith 46269ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), 46369ce434fSBarry Smith PetscLayoutGetSize(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 46469ce434fSBarry Smith @*/ 46569ce434fSBarry Smith PetscErrorCode PetscLayoutGetRange(PetscLayout map,PetscInt *rstart,PetscInt *rend) 46669ce434fSBarry Smith { 46769ce434fSBarry Smith PetscFunctionBegin; 46869ce434fSBarry Smith if (rstart) *rstart = map->rstart; 46969ce434fSBarry Smith if (rend) *rend = map->rend; 47069ce434fSBarry Smith PetscFunctionReturn(0); 47169ce434fSBarry Smith } 47269ce434fSBarry Smith 47369ce434fSBarry Smith /*@C 47469ce434fSBarry Smith PetscLayoutGetRanges - gets the range of values owned by all processes 47569ce434fSBarry Smith 47669ce434fSBarry Smith Not Collective 47769ce434fSBarry Smith 47869ce434fSBarry Smith Input Parameters: 47969ce434fSBarry Smith . map - pointer to the map 48069ce434fSBarry Smith 48169ce434fSBarry Smith Output Parameters: 48269ce434fSBarry Smith . range - start of each processors range of indices (the final entry is one more then the 48369ce434fSBarry Smith last index on the last process) 48469ce434fSBarry Smith 48569ce434fSBarry Smith Level: developer 48669ce434fSBarry Smith 48769ce434fSBarry Smith Notes: 48869ce434fSBarry Smith Call this after the call to PetscLayoutSetUp() 48969ce434fSBarry Smith 49069ce434fSBarry Smith Fortran Notes: 49169ce434fSBarry Smith Not available from Fortran 49269ce434fSBarry Smith 49369ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), 49469ce434fSBarry Smith PetscLayoutGetSize(), PetscLayoutGetRange(), PetscLayoutSetBlockSize(), PetscLayoutGetSize(), PetscLayoutSetUp() 49569ce434fSBarry Smith 49669ce434fSBarry Smith @*/ 49769ce434fSBarry Smith #undef __FUNCT__ 49869ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetRanges" 49969ce434fSBarry Smith PetscErrorCode PetscLayoutGetRanges(PetscLayout map,const PetscInt *range[]) 50069ce434fSBarry Smith { 50169ce434fSBarry Smith PetscFunctionBegin; 50269ce434fSBarry Smith *range = map->range; 50369ce434fSBarry Smith PetscFunctionReturn(0); 50469ce434fSBarry Smith } 50569ce434fSBarry Smith 50669ce434fSBarry Smith #undef __FUNCT__ 50769ce434fSBarry Smith #define __FUNCT__ "PetscSFSetGraphLayout" 50869ce434fSBarry Smith /*@C 50969ce434fSBarry Smith PetscSFSetGraphLayout - Set a parallel star forest via global indices and a PetscLayout 51069ce434fSBarry Smith 51169ce434fSBarry Smith Collective 51269ce434fSBarry Smith 51369ce434fSBarry Smith Input Arguments: 51469ce434fSBarry Smith + sf - star forest 51569ce434fSBarry Smith . layout - PetscLayout defining the global space 51669ce434fSBarry Smith . nleaves - number of leaf vertices on the current process, each of these references a root on any process 51769ce434fSBarry Smith . ilocal - locations of leaves in leafdata buffers, pass NULL for contiguous storage 51869ce434fSBarry Smith - iremote - remote locations of root vertices for each leaf on the current process 51969ce434fSBarry Smith 52069ce434fSBarry Smith Level: intermediate 52169ce434fSBarry Smith 52269ce434fSBarry Smith .seealso: PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph() 52369ce434fSBarry Smith @*/ 52469ce434fSBarry Smith PetscErrorCode PetscSFSetGraphLayout(PetscSF sf,PetscLayout layout,PetscInt nleaves,const PetscInt *ilocal,PetscCopyMode localmode,const PetscInt *iremote) 52569ce434fSBarry Smith { 52669ce434fSBarry Smith PetscErrorCode ierr; 52769ce434fSBarry Smith PetscInt i,nroots; 52869ce434fSBarry Smith PetscSFNode *remote; 52969ce434fSBarry Smith 53069ce434fSBarry Smith PetscFunctionBegin; 53169ce434fSBarry Smith ierr = PetscLayoutGetLocalSize(layout,&nroots);CHKERRQ(ierr); 532785e854fSJed Brown ierr = PetscMalloc1(nleaves,&remote);CHKERRQ(ierr); 53369ce434fSBarry Smith for (i=0; i<nleaves; i++) { 53469ce434fSBarry Smith PetscInt owner = -1; 53569ce434fSBarry Smith ierr = PetscLayoutFindOwner(layout,iremote[i],&owner);CHKERRQ(ierr); 53669ce434fSBarry Smith remote[i].rank = owner; 53769ce434fSBarry Smith remote[i].index = iremote[i] - layout->range[owner]; 53869ce434fSBarry Smith } 53969ce434fSBarry Smith ierr = PetscSFSetGraph(sf,nroots,nleaves,ilocal,localmode,remote,PETSC_OWN_POINTER);CHKERRQ(ierr); 54069ce434fSBarry Smith PetscFunctionReturn(0); 54169ce434fSBarry Smith } 54269ce434fSBarry Smith 543