xref: /petsc/src/vec/is/utils/pmap.c (revision 0c312b8e6c5493a795e997bb0b5f8ef7b1287755)
169ce434fSBarry Smith 
269ce434fSBarry Smith /*
369ce434fSBarry Smith    This file contains routines for basic map object implementation.
469ce434fSBarry Smith */
569ce434fSBarry Smith 
669ce434fSBarry Smith #include <petscvec.h>
7*0c312b8eSJed Brown #include <petscsf.h>
869ce434fSBarry Smith #include <petsc-private/threadcommimpl.h>
969ce434fSBarry Smith #undef __FUNCT__
1069ce434fSBarry Smith #define __FUNCT__ "PetscLayoutCreate"
1169ce434fSBarry Smith /*@C
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 
2069ce434fSBarry Smith    Level: developer
2169ce434fSBarry Smith 
2269ce434fSBarry Smith     Notes: Typical calling sequence
2369ce434fSBarry Smith        PetscLayoutCreate(MPI_Comm,PetscLayout *);
2469ce434fSBarry Smith        PetscLayoutSetBlockSize(PetscLayout,1);
2569ce434fSBarry Smith        PetscLayoutSetSize(PetscLayout,n) or PetscLayoutSetLocalSize(PetscLayout,N);
2669ce434fSBarry Smith        PetscLayoutSetUp(PetscLayout);
2769ce434fSBarry Smith        Optionally use any of the following:
2869ce434fSBarry Smith           PetscLayoutGetSize(PetscLayout,PetscInt *); or PetscLayoutGetLocalSize(PetscLayout,PetscInt *;)
2969ce434fSBarry Smith           PetscLayoutGetRange(PetscLayout,PetscInt *rstart,PetscInt *rend); or PetscLayoutGetRanges(PetscLayout,const PetscInt *range[])
3069ce434fSBarry Smith        PetscLayoutDestroy(PetscLayout);
3169ce434fSBarry Smith 
3269ce434fSBarry Smith       The PetscLayout object and methods are intended to be used in the PETSc Vec and Mat implementions; it is often not needed in
3369ce434fSBarry Smith       user codes unless you really gain something in their use.
3469ce434fSBarry Smith 
3569ce434fSBarry Smith     Fortran Notes:
3669ce434fSBarry Smith       Not available from Fortran
3769ce434fSBarry Smith 
3869ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutDestroy(),
3969ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutSetUp()
4069ce434fSBarry Smith 
4169ce434fSBarry Smith @*/
4269ce434fSBarry Smith PetscErrorCode  PetscLayoutCreate(MPI_Comm comm,PetscLayout *map)
4369ce434fSBarry Smith {
4469ce434fSBarry Smith   PetscErrorCode ierr;
4569ce434fSBarry Smith 
4669ce434fSBarry Smith   PetscFunctionBegin;
4769ce434fSBarry Smith   ierr = PetscNew(struct _n_PetscLayout,map);CHKERRQ(ierr);
4869ce434fSBarry Smith 
4969ce434fSBarry Smith   (*map)->comm   = comm;
5069ce434fSBarry Smith   (*map)->bs     = -1;
5169ce434fSBarry Smith   (*map)->n      = -1;
5269ce434fSBarry Smith   (*map)->N      = -1;
5369ce434fSBarry Smith   (*map)->range  = 0;
5469ce434fSBarry Smith   (*map)->rstart = 0;
5569ce434fSBarry Smith   (*map)->rend   = 0;
5669ce434fSBarry Smith   (*map)->trstarts = 0;
5769ce434fSBarry Smith   PetscFunctionReturn(0);
5869ce434fSBarry Smith }
5969ce434fSBarry Smith 
6069ce434fSBarry Smith /*@C
6169ce434fSBarry Smith      PetscLayoutDestroy - Frees a map object and frees its range if that exists.
6269ce434fSBarry Smith 
6369ce434fSBarry Smith     Collective on MPI_Comm
6469ce434fSBarry Smith 
6569ce434fSBarry Smith    Input Parameters:
6669ce434fSBarry Smith .    map - the PetscLayout
6769ce434fSBarry Smith 
6869ce434fSBarry Smith    Level: developer
6969ce434fSBarry Smith 
7069ce434fSBarry Smith       The PetscLayout object and methods are intended to be used in the PETSc Vec and Mat implementions; it is
7169ce434fSBarry Smith       recommended they not be used in user codes unless you really gain something in their use.
7269ce434fSBarry Smith 
7369ce434fSBarry Smith     Fortran Notes:
7469ce434fSBarry Smith       Not available from Fortran
7569ce434fSBarry Smith 
7669ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutCreate(),
7769ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutSetUp()
7869ce434fSBarry Smith 
7969ce434fSBarry Smith @*/
8069ce434fSBarry Smith #undef __FUNCT__
8169ce434fSBarry Smith #define __FUNCT__ "PetscLayoutDestroy"
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 = ISLocalToGlobalMappingDestroy(&(*map)->bmapping);CHKERRQ(ierr);
9269ce434fSBarry Smith #if defined(PETSC_THREADCOMM_ACTIVE)
9369ce434fSBarry Smith     ierr = PetscFree((*map)->trstarts);CHKERRQ(ierr);
9469ce434fSBarry Smith #endif
9569ce434fSBarry Smith 
9669ce434fSBarry Smith     ierr = PetscFree((*map));CHKERRQ(ierr);
9769ce434fSBarry Smith   }
9869ce434fSBarry Smith   *map = NULL;
9969ce434fSBarry Smith   PetscFunctionReturn(0);
10069ce434fSBarry Smith }
10169ce434fSBarry Smith 
10269ce434fSBarry Smith /*@C
10369ce434fSBarry Smith      PetscLayoutSetUp - given a map where you have set either the global or local
10469ce434fSBarry Smith            size sets up the map so that it may be used.
10569ce434fSBarry Smith 
10669ce434fSBarry Smith     Collective on MPI_Comm
10769ce434fSBarry Smith 
10869ce434fSBarry Smith    Input Parameters:
10969ce434fSBarry Smith .    map - pointer to the map
11069ce434fSBarry Smith 
11169ce434fSBarry Smith    Level: developer
11269ce434fSBarry Smith 
11369ce434fSBarry Smith     Notes: Typical calling sequence
11469ce434fSBarry Smith        PetscLayoutCreate(MPI_Comm,PetscLayout *);
11569ce434fSBarry Smith        PetscLayoutSetBlockSize(PetscLayout,1);
11669ce434fSBarry Smith        PetscLayoutSetSize(PetscLayout,n) or PetscLayoutSetLocalSize(PetscLayout,N); or both
11769ce434fSBarry Smith        PetscLayoutSetUp(PetscLayout);
11869ce434fSBarry Smith        PetscLayoutGetSize(PetscLayout,PetscInt *);
11969ce434fSBarry Smith 
12069ce434fSBarry Smith 
12169ce434fSBarry Smith        If the local size, global size are already set and range exists then this does nothing.
12269ce434fSBarry Smith 
12369ce434fSBarry Smith     Fortran Notes:
12469ce434fSBarry Smith       Not available from Fortran
12569ce434fSBarry Smith 
12669ce434fSBarry Smith .seealso: PetscLayoutSetLocalSize(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayout, PetscLayoutDestroy(),
12769ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize(), PetscLayoutCreate()
12869ce434fSBarry Smith 
12969ce434fSBarry Smith @*/
13069ce434fSBarry Smith #undef __FUNCT__
13169ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetUp"
13269ce434fSBarry Smith PetscErrorCode  PetscLayoutSetUp(PetscLayout map)
13369ce434fSBarry Smith {
13469ce434fSBarry Smith   PetscMPIInt    rank,size;
13569ce434fSBarry Smith   PetscInt       p;
13669ce434fSBarry Smith   PetscErrorCode ierr;
13769ce434fSBarry Smith 
13869ce434fSBarry Smith   PetscFunctionBegin;
13969ce434fSBarry Smith   if (map->bs <= 0) map->bs = 1;
14069ce434fSBarry Smith   if ((map->n >= 0) && (map->N >= 0) && (map->range)) PetscFunctionReturn(0);
14169ce434fSBarry Smith 
14269ce434fSBarry Smith   ierr = MPI_Comm_size(map->comm, &size);CHKERRQ(ierr);
14369ce434fSBarry Smith   ierr = MPI_Comm_rank(map->comm, &rank);CHKERRQ(ierr);
14469ce434fSBarry Smith   if (map->n > 0) map->n = map->n/map->bs;
14569ce434fSBarry Smith   if (map->N > 0) map->N = map->N/map->bs;
14669ce434fSBarry Smith   ierr = PetscSplitOwnership(map->comm,&map->n,&map->N);CHKERRQ(ierr);
14769ce434fSBarry Smith   map->n = map->n*map->bs;
14869ce434fSBarry Smith   map->N = map->N*map->bs;
14969ce434fSBarry Smith   if (!map->range) {
15069ce434fSBarry Smith     ierr = PetscMalloc((size+1)*sizeof(PetscInt), &map->range);CHKERRQ(ierr);
15169ce434fSBarry Smith   }
15269ce434fSBarry Smith   ierr = MPI_Allgather(&map->n, 1, MPIU_INT, map->range+1, 1, MPIU_INT, map->comm);CHKERRQ(ierr);
15369ce434fSBarry Smith 
15469ce434fSBarry Smith   map->range[0] = 0;
15569ce434fSBarry Smith   for (p = 2; p <= size; p++) map->range[p] += map->range[p-1];
15669ce434fSBarry Smith 
15769ce434fSBarry Smith   map->rstart = map->range[rank];
15869ce434fSBarry Smith   map->rend   = map->range[rank+1];
15969ce434fSBarry Smith #if defined(PETSC_THREADCOMM_ACTIVE)
16069ce434fSBarry Smith   /* Set the thread ownership ranges */
16169ce434fSBarry Smith   ierr = PetscThreadCommGetOwnershipRanges(map->comm,map->n,&map->trstarts);CHKERRQ(ierr);
16269ce434fSBarry Smith #endif
16369ce434fSBarry Smith   PetscFunctionReturn(0);
16469ce434fSBarry Smith }
16569ce434fSBarry Smith 
16669ce434fSBarry Smith #undef __FUNCT__
16769ce434fSBarry Smith #define __FUNCT__ "PetscLayoutDuplicate"
16869ce434fSBarry Smith /*@C
16969ce434fSBarry Smith 
17069ce434fSBarry Smith     PetscLayoutDuplicate - creates a new PetscLayout with the same information as a given one. If the PetscLayout already exists it is destroyed first.
17169ce434fSBarry Smith 
17269ce434fSBarry Smith      Collective on PetscLayout
17369ce434fSBarry Smith 
17469ce434fSBarry Smith     Input Parameter:
17569ce434fSBarry Smith .     in - input PetscLayout to be duplicated
17669ce434fSBarry Smith 
17769ce434fSBarry Smith     Output Parameter:
17869ce434fSBarry Smith .     out - the copy
17969ce434fSBarry Smith 
18069ce434fSBarry Smith    Level: developer
18169ce434fSBarry Smith 
18269ce434fSBarry Smith     Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout
18369ce434fSBarry Smith 
18469ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutReference()
18569ce434fSBarry Smith 
18669ce434fSBarry Smith @*/
18769ce434fSBarry Smith PetscErrorCode  PetscLayoutDuplicate(PetscLayout in,PetscLayout *out)
18869ce434fSBarry Smith {
18969ce434fSBarry Smith   PetscMPIInt    size;
19069ce434fSBarry Smith   PetscErrorCode ierr;
19169ce434fSBarry Smith   MPI_Comm       comm = in->comm;
19269ce434fSBarry Smith 
19369ce434fSBarry Smith   PetscFunctionBegin;
19469ce434fSBarry Smith   ierr = PetscLayoutDestroy(out);CHKERRQ(ierr);
19569ce434fSBarry Smith   ierr = PetscLayoutCreate(comm,out);CHKERRQ(ierr);
19669ce434fSBarry Smith   ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
19769ce434fSBarry Smith   ierr = PetscMemcpy(*out,in,sizeof(struct _n_PetscLayout));CHKERRQ(ierr);
19869ce434fSBarry Smith   ierr = PetscMalloc((size+1)*sizeof(PetscInt),&(*out)->range);CHKERRQ(ierr);
19969ce434fSBarry Smith   ierr = PetscMemcpy((*out)->range,in->range,(size+1)*sizeof(PetscInt));CHKERRQ(ierr);
20069ce434fSBarry Smith 
20169ce434fSBarry Smith   (*out)->refcnt = 0;
20269ce434fSBarry Smith   PetscFunctionReturn(0);
20369ce434fSBarry Smith }
20469ce434fSBarry Smith 
20569ce434fSBarry Smith #undef __FUNCT__
20669ce434fSBarry Smith #define __FUNCT__ "PetscLayoutReference"
20769ce434fSBarry Smith /*@C
20869ce434fSBarry Smith 
20969ce434fSBarry Smith     PetscLayoutReference - Causes a PETSc Vec or Mat to share a PetscLayout with one that already exists. Used by Vec/MatDuplicate_XXX()
21069ce434fSBarry Smith 
21169ce434fSBarry Smith      Collective on PetscLayout
21269ce434fSBarry Smith 
21369ce434fSBarry Smith     Input Parameter:
21469ce434fSBarry Smith .     in - input PetscLayout to be copied
21569ce434fSBarry Smith 
21669ce434fSBarry Smith     Output Parameter:
21769ce434fSBarry Smith .     out - the reference location
21869ce434fSBarry Smith 
21969ce434fSBarry Smith    Level: developer
22069ce434fSBarry Smith 
22169ce434fSBarry Smith     Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout
22269ce434fSBarry Smith 
22369ce434fSBarry Smith     If the out location already contains a PetscLayout it is destroyed
22469ce434fSBarry Smith 
22569ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate()
22669ce434fSBarry Smith 
22769ce434fSBarry Smith @*/
22869ce434fSBarry Smith PetscErrorCode  PetscLayoutReference(PetscLayout in,PetscLayout *out)
22969ce434fSBarry Smith {
23069ce434fSBarry Smith   PetscErrorCode ierr;
23169ce434fSBarry Smith 
23269ce434fSBarry Smith   PetscFunctionBegin;
23369ce434fSBarry Smith   in->refcnt++;
23469ce434fSBarry Smith   ierr = PetscLayoutDestroy(out);CHKERRQ(ierr);
23569ce434fSBarry Smith   *out = in;
23669ce434fSBarry Smith   PetscFunctionReturn(0);
23769ce434fSBarry Smith }
23869ce434fSBarry Smith 
23969ce434fSBarry Smith #undef __FUNCT__
24069ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetISLocalToGlobalMapping"
24169ce434fSBarry Smith /*@C
24269ce434fSBarry Smith 
24369ce434fSBarry Smith     PetscLayoutSetISLocalToGlobalMapping - sets a ISLocalGlobalMapping into a PetscLayout
24469ce434fSBarry Smith 
24569ce434fSBarry Smith      Collective on PetscLayout
24669ce434fSBarry Smith 
24769ce434fSBarry Smith     Input Parameter:
24869ce434fSBarry Smith +     in - input PetscLayout
24969ce434fSBarry Smith -     ltog - the local to global mapping
25069ce434fSBarry Smith 
25169ce434fSBarry Smith 
25269ce434fSBarry Smith    Level: developer
25369ce434fSBarry Smith 
25469ce434fSBarry Smith     Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout
25569ce434fSBarry Smith 
25669ce434fSBarry Smith     If the ltog location already contains a PetscLayout it is destroyed
25769ce434fSBarry Smith 
25869ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate(), PetscLayoutSetLocalToGlobalMappingBlock()
25969ce434fSBarry Smith 
26069ce434fSBarry Smith @*/
26169ce434fSBarry Smith PetscErrorCode  PetscLayoutSetISLocalToGlobalMapping(PetscLayout in,ISLocalToGlobalMapping ltog)
26269ce434fSBarry Smith {
26369ce434fSBarry Smith   PetscErrorCode ierr;
26469ce434fSBarry Smith 
26569ce434fSBarry Smith   PetscFunctionBegin;
26669ce434fSBarry Smith   ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr);
26769ce434fSBarry Smith   ierr = ISLocalToGlobalMappingDestroy(&in->mapping);CHKERRQ(ierr);
26869ce434fSBarry Smith 
26969ce434fSBarry Smith   in->mapping = ltog;
27069ce434fSBarry Smith   PetscFunctionReturn(0);
27169ce434fSBarry Smith }
27269ce434fSBarry Smith 
27369ce434fSBarry Smith #undef __FUNCT__
27469ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetISLocalToGlobalMappingBlock"
27569ce434fSBarry Smith /*@C
27669ce434fSBarry Smith 
27769ce434fSBarry Smith     PetscLayoutSetISLocalToGlobalMappingBlock - sets a ISLocalGlobalMapping into a PetscLayout
27869ce434fSBarry Smith 
27969ce434fSBarry Smith      Collective on PetscLayout
28069ce434fSBarry Smith 
28169ce434fSBarry Smith     Input Parameter:
28269ce434fSBarry Smith +     in - input PetscLayout
28369ce434fSBarry Smith -     ltog - the local to global block mapping
28469ce434fSBarry Smith 
28569ce434fSBarry Smith 
28669ce434fSBarry Smith    Level: developer
28769ce434fSBarry Smith 
28869ce434fSBarry Smith     Notes: PetscLayoutSetUp() does not need to be called on the resulting PetscLayout
28969ce434fSBarry Smith 
29069ce434fSBarry Smith     If the ltog location already contains a PetscLayout it is destroyed
29169ce434fSBarry Smith 
29269ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutDestroy(), PetscLayoutSetUp(), PetscLayoutDuplicate(), PetscLayoutSetLocalToGlobalMappingBlock()
29369ce434fSBarry Smith 
29469ce434fSBarry Smith @*/
29569ce434fSBarry Smith PetscErrorCode  PetscLayoutSetISLocalToGlobalMappingBlock(PetscLayout in,ISLocalToGlobalMapping ltog)
29669ce434fSBarry Smith {
29769ce434fSBarry Smith   PetscErrorCode ierr;
29869ce434fSBarry Smith 
29969ce434fSBarry Smith   PetscFunctionBegin;
30069ce434fSBarry Smith   ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr);
30169ce434fSBarry Smith   ierr = ISLocalToGlobalMappingDestroy(&in->bmapping);CHKERRQ(ierr);
30269ce434fSBarry Smith 
30369ce434fSBarry Smith   in->bmapping = ltog;
30469ce434fSBarry Smith   PetscFunctionReturn(0);
30569ce434fSBarry Smith }
30669ce434fSBarry Smith 
30769ce434fSBarry Smith /*@C
30869ce434fSBarry Smith      PetscLayoutSetLocalSize - Sets the local size for a PetscLayout object.
30969ce434fSBarry Smith 
31069ce434fSBarry Smith     Collective on PetscLayout
31169ce434fSBarry Smith 
31269ce434fSBarry Smith    Input Parameters:
31369ce434fSBarry Smith +    map - pointer to the map
31469ce434fSBarry Smith -    n - the local size
31569ce434fSBarry Smith 
31669ce434fSBarry Smith    Level: developer
31769ce434fSBarry Smith 
31869ce434fSBarry Smith     Notes:
31969ce434fSBarry Smith        Call this after the call to PetscLayoutCreate()
32069ce434fSBarry Smith 
32169ce434fSBarry Smith     Fortran Notes:
32269ce434fSBarry Smith       Not available from Fortran
32369ce434fSBarry Smith 
32469ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayoutSetUp()
32569ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize()
32669ce434fSBarry Smith 
32769ce434fSBarry Smith @*/
32869ce434fSBarry Smith #undef __FUNCT__
32969ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetLocalSize"
33069ce434fSBarry Smith PetscErrorCode  PetscLayoutSetLocalSize(PetscLayout map,PetscInt n)
33169ce434fSBarry Smith {
33269ce434fSBarry Smith   PetscFunctionBegin;
33369ce434fSBarry 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);
33469ce434fSBarry Smith   map->n = n;
33569ce434fSBarry Smith   PetscFunctionReturn(0);
33669ce434fSBarry Smith }
33769ce434fSBarry Smith 
33869ce434fSBarry Smith /*@C
33969ce434fSBarry Smith      PetscLayoutGetLocalSize - Gets the local size for a PetscLayout object.
34069ce434fSBarry Smith 
34169ce434fSBarry Smith     Not Collective
34269ce434fSBarry Smith 
34369ce434fSBarry Smith    Input Parameters:
34469ce434fSBarry Smith .    map - pointer to the map
34569ce434fSBarry Smith 
34669ce434fSBarry Smith    Output Parameters:
34769ce434fSBarry Smith .    n - the local size
34869ce434fSBarry Smith 
34969ce434fSBarry Smith    Level: developer
35069ce434fSBarry Smith 
35169ce434fSBarry Smith     Notes:
35269ce434fSBarry Smith        Call this after the call to PetscLayoutSetUp()
35369ce434fSBarry Smith 
35469ce434fSBarry Smith     Fortran Notes:
35569ce434fSBarry Smith       Not available from Fortran
35669ce434fSBarry Smith 
35769ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutGetLocalSize(), PetscLayoutSetUp()
35869ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize()
35969ce434fSBarry Smith 
36069ce434fSBarry Smith @*/
36169ce434fSBarry Smith #undef __FUNCT__
36269ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetLocalSize"
36369ce434fSBarry Smith PetscErrorCode  PetscLayoutGetLocalSize(PetscLayout map,PetscInt *n)
36469ce434fSBarry Smith {
36569ce434fSBarry Smith   PetscFunctionBegin;
36669ce434fSBarry Smith   *n = map->n;
36769ce434fSBarry Smith   PetscFunctionReturn(0);
36869ce434fSBarry Smith }
36969ce434fSBarry Smith 
37069ce434fSBarry Smith /*@C
37169ce434fSBarry Smith      PetscLayoutSetSize - Sets the global size for a PetscLayout object.
37269ce434fSBarry Smith 
37369ce434fSBarry Smith     Logically Collective on PetscLayout
37469ce434fSBarry Smith 
37569ce434fSBarry Smith    Input Parameters:
37669ce434fSBarry Smith +    map - pointer to the map
37769ce434fSBarry Smith -    n - the global size
37869ce434fSBarry Smith 
37969ce434fSBarry Smith    Level: developer
38069ce434fSBarry Smith 
38169ce434fSBarry Smith     Notes:
38269ce434fSBarry Smith        Call this after the call to PetscLayoutCreate()
38369ce434fSBarry Smith 
38469ce434fSBarry Smith     Fortran Notes:
38569ce434fSBarry Smith       Not available from Fortran
38669ce434fSBarry Smith 
38769ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutGetSize(), PetscLayoutSetUp()
38869ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize()
38969ce434fSBarry Smith 
39069ce434fSBarry Smith @*/
39169ce434fSBarry Smith #undef __FUNCT__
39269ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetSize"
39369ce434fSBarry Smith PetscErrorCode  PetscLayoutSetSize(PetscLayout map,PetscInt n)
39469ce434fSBarry Smith {
39569ce434fSBarry Smith   PetscFunctionBegin;
39669ce434fSBarry Smith   map->N = n;
39769ce434fSBarry Smith   PetscFunctionReturn(0);
39869ce434fSBarry Smith }
39969ce434fSBarry Smith 
40069ce434fSBarry Smith /*@C
40169ce434fSBarry Smith      PetscLayoutGetSize - Gets the global size for a PetscLayout object.
40269ce434fSBarry Smith 
40369ce434fSBarry Smith     Not Collective
40469ce434fSBarry Smith 
40569ce434fSBarry Smith    Input Parameters:
40669ce434fSBarry Smith .    map - pointer to the map
40769ce434fSBarry Smith 
40869ce434fSBarry Smith    Output Parameters:
40969ce434fSBarry Smith .    n - the global size
41069ce434fSBarry Smith 
41169ce434fSBarry Smith    Level: developer
41269ce434fSBarry Smith 
41369ce434fSBarry Smith     Notes:
41469ce434fSBarry Smith        Call this after the call to PetscLayoutSetUp()
41569ce434fSBarry Smith 
41669ce434fSBarry Smith     Fortran Notes:
41769ce434fSBarry Smith       Not available from Fortran
41869ce434fSBarry Smith 
41969ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), PetscLayoutSetUp()
42069ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetBlockSize()
42169ce434fSBarry Smith 
42269ce434fSBarry Smith @*/
42369ce434fSBarry Smith #undef __FUNCT__
42469ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetSize"
42569ce434fSBarry Smith PetscErrorCode  PetscLayoutGetSize(PetscLayout map,PetscInt *n)
42669ce434fSBarry Smith {
42769ce434fSBarry Smith   PetscFunctionBegin;
42869ce434fSBarry Smith   *n = map->N;
42969ce434fSBarry Smith   PetscFunctionReturn(0);
43069ce434fSBarry Smith }
43169ce434fSBarry Smith 
43269ce434fSBarry Smith /*@C
43369ce434fSBarry Smith      PetscLayoutSetBlockSize - Sets the block size for a PetscLayout object.
43469ce434fSBarry Smith 
43569ce434fSBarry Smith     Logically Collective on PetscLayout
43669ce434fSBarry Smith 
43769ce434fSBarry Smith    Input Parameters:
43869ce434fSBarry Smith +    map - pointer to the map
43969ce434fSBarry Smith -    bs - the size
44069ce434fSBarry Smith 
44169ce434fSBarry Smith    Level: developer
44269ce434fSBarry Smith 
44369ce434fSBarry Smith     Notes:
44469ce434fSBarry Smith        Call this after the call to PetscLayoutCreate()
44569ce434fSBarry Smith 
44669ce434fSBarry Smith     Fortran Notes:
44769ce434fSBarry Smith       Not available from Fortran
44869ce434fSBarry Smith 
44969ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutGetBlockSize(),
45069ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetSize(), PetscLayoutGetSize(), PetscLayoutSetUp()
45169ce434fSBarry Smith 
45269ce434fSBarry Smith @*/
45369ce434fSBarry Smith #undef __FUNCT__
45469ce434fSBarry Smith #define __FUNCT__ "PetscLayoutSetBlockSize"
45569ce434fSBarry Smith PetscErrorCode  PetscLayoutSetBlockSize(PetscLayout map,PetscInt bs)
45669ce434fSBarry Smith {
45769ce434fSBarry Smith   PetscFunctionBegin;
45869ce434fSBarry 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);
45969ce434fSBarry 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);
46069ce434fSBarry Smith   map->bs = bs;
46169ce434fSBarry Smith   PetscFunctionReturn(0);
46269ce434fSBarry Smith }
46369ce434fSBarry Smith 
46469ce434fSBarry Smith /*@C
46569ce434fSBarry Smith      PetscLayoutGetBlockSize - Gets the block size for a PetscLayout object.
46669ce434fSBarry Smith 
46769ce434fSBarry Smith     Not Collective
46869ce434fSBarry Smith 
46969ce434fSBarry Smith    Input Parameters:
47069ce434fSBarry Smith .    map - pointer to the map
47169ce434fSBarry Smith 
47269ce434fSBarry Smith    Output Parameters:
47369ce434fSBarry Smith .    bs - the size
47469ce434fSBarry Smith 
47569ce434fSBarry Smith    Level: developer
47669ce434fSBarry Smith 
47769ce434fSBarry Smith     Notes:
47869ce434fSBarry Smith        Call this after the call to PetscLayoutSetUp()
47969ce434fSBarry Smith 
48069ce434fSBarry Smith     Fortran Notes:
48169ce434fSBarry Smith       Not available from Fortran
48269ce434fSBarry Smith 
48369ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(), PetscLayoutSetUp()
48469ce434fSBarry Smith           PetscLayoutGetRange(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetSize()
48569ce434fSBarry Smith 
48669ce434fSBarry Smith @*/
48769ce434fSBarry Smith #undef __FUNCT__
48869ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetBlockSize"
48969ce434fSBarry Smith PetscErrorCode  PetscLayoutGetBlockSize(PetscLayout map,PetscInt *bs)
49069ce434fSBarry Smith {
49169ce434fSBarry Smith   PetscFunctionBegin;
49269ce434fSBarry Smith   *bs = map->bs;
49369ce434fSBarry Smith   PetscFunctionReturn(0);
49469ce434fSBarry Smith }
49569ce434fSBarry Smith 
49669ce434fSBarry Smith 
49769ce434fSBarry Smith /*@C
49869ce434fSBarry Smith      PetscLayoutGetRange - gets the range of values owned by this process
49969ce434fSBarry Smith 
50069ce434fSBarry Smith     Not Collective
50169ce434fSBarry Smith 
50269ce434fSBarry Smith    Input Parameters:
50369ce434fSBarry Smith .    map - pointer to the map
50469ce434fSBarry Smith 
50569ce434fSBarry Smith    Output Parameters:
50669ce434fSBarry Smith +    rstart - first index owned by this process
50769ce434fSBarry Smith -    rend - one more than the last index owned by this process
50869ce434fSBarry Smith 
50969ce434fSBarry Smith    Level: developer
51069ce434fSBarry Smith 
51169ce434fSBarry Smith     Notes:
51269ce434fSBarry Smith        Call this after the call to PetscLayoutSetUp()
51369ce434fSBarry Smith 
51469ce434fSBarry Smith     Fortran Notes:
51569ce434fSBarry Smith       Not available from Fortran
51669ce434fSBarry Smith 
51769ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(),
51869ce434fSBarry Smith           PetscLayoutGetSize(), PetscLayoutGetRanges(), PetscLayoutSetBlockSize(), PetscLayoutGetSize(), PetscLayoutSetUp()
51969ce434fSBarry Smith 
52069ce434fSBarry Smith @*/
52169ce434fSBarry Smith #undef __FUNCT__
52269ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetRange"
52369ce434fSBarry Smith PetscErrorCode  PetscLayoutGetRange(PetscLayout map,PetscInt *rstart,PetscInt *rend)
52469ce434fSBarry Smith {
52569ce434fSBarry Smith   PetscFunctionBegin;
52669ce434fSBarry Smith   if (rstart) *rstart = map->rstart;
52769ce434fSBarry Smith   if (rend)   *rend   = map->rend;
52869ce434fSBarry Smith   PetscFunctionReturn(0);
52969ce434fSBarry Smith }
53069ce434fSBarry Smith 
53169ce434fSBarry Smith /*@C
53269ce434fSBarry Smith      PetscLayoutGetRanges - gets the range of values owned by all processes
53369ce434fSBarry Smith 
53469ce434fSBarry Smith     Not Collective
53569ce434fSBarry Smith 
53669ce434fSBarry Smith    Input Parameters:
53769ce434fSBarry Smith .    map - pointer to the map
53869ce434fSBarry Smith 
53969ce434fSBarry Smith    Output Parameters:
54069ce434fSBarry Smith .    range - start of each processors range of indices (the final entry is one more then the
54169ce434fSBarry Smith              last index on the last process)
54269ce434fSBarry Smith 
54369ce434fSBarry Smith    Level: developer
54469ce434fSBarry Smith 
54569ce434fSBarry Smith     Notes:
54669ce434fSBarry Smith        Call this after the call to PetscLayoutSetUp()
54769ce434fSBarry Smith 
54869ce434fSBarry Smith     Fortran Notes:
54969ce434fSBarry Smith       Not available from Fortran
55069ce434fSBarry Smith 
55169ce434fSBarry Smith .seealso: PetscLayoutCreate(), PetscLayoutSetLocalSize(), PetscLayoutGetLocalSize(), PetscLayoutSetSize(),
55269ce434fSBarry Smith           PetscLayoutGetSize(), PetscLayoutGetRange(), PetscLayoutSetBlockSize(), PetscLayoutGetSize(), PetscLayoutSetUp()
55369ce434fSBarry Smith 
55469ce434fSBarry Smith @*/
55569ce434fSBarry Smith #undef __FUNCT__
55669ce434fSBarry Smith #define __FUNCT__ "PetscLayoutGetRanges"
55769ce434fSBarry Smith PetscErrorCode  PetscLayoutGetRanges(PetscLayout map,const PetscInt *range[])
55869ce434fSBarry Smith {
55969ce434fSBarry Smith   PetscFunctionBegin;
56069ce434fSBarry Smith   *range = map->range;
56169ce434fSBarry Smith   PetscFunctionReturn(0);
56269ce434fSBarry Smith }
56369ce434fSBarry Smith 
56469ce434fSBarry Smith #undef __FUNCT__
56569ce434fSBarry Smith #define __FUNCT__ "PetscSFSetGraphLayout"
56669ce434fSBarry Smith /*@C
56769ce434fSBarry Smith    PetscSFSetGraphLayout - Set a parallel star forest via global indices and a PetscLayout
56869ce434fSBarry Smith 
56969ce434fSBarry Smith    Collective
57069ce434fSBarry Smith 
57169ce434fSBarry Smith    Input Arguments:
57269ce434fSBarry Smith +  sf - star forest
57369ce434fSBarry Smith .  layout - PetscLayout defining the global space
57469ce434fSBarry Smith .  nleaves - number of leaf vertices on the current process, each of these references a root on any process
57569ce434fSBarry Smith .  ilocal - locations of leaves in leafdata buffers, pass NULL for contiguous storage
57669ce434fSBarry Smith -  iremote - remote locations of root vertices for each leaf on the current process
57769ce434fSBarry Smith 
57869ce434fSBarry Smith    Level: intermediate
57969ce434fSBarry Smith 
58069ce434fSBarry Smith .seealso: PetscSFCreate(), PetscSFView(), PetscSFSetGraph(), PetscSFGetGraph()
58169ce434fSBarry Smith @*/
58269ce434fSBarry Smith PetscErrorCode PetscSFSetGraphLayout(PetscSF sf,PetscLayout layout,PetscInt nleaves,const PetscInt *ilocal,PetscCopyMode localmode,const PetscInt *iremote)
58369ce434fSBarry Smith {
58469ce434fSBarry Smith   PetscErrorCode ierr;
58569ce434fSBarry Smith   PetscInt       i,nroots;
58669ce434fSBarry Smith   PetscSFNode    *remote;
58769ce434fSBarry Smith 
58869ce434fSBarry Smith   PetscFunctionBegin;
58969ce434fSBarry Smith   ierr = PetscLayoutGetLocalSize(layout,&nroots);CHKERRQ(ierr);
59069ce434fSBarry Smith   ierr = PetscMalloc(nleaves*sizeof(PetscSFNode),&remote);CHKERRQ(ierr);
59169ce434fSBarry Smith   for (i=0; i<nleaves; i++) {
59269ce434fSBarry Smith     PetscInt owner = -1;
59369ce434fSBarry Smith     ierr = PetscLayoutFindOwner(layout,iremote[i],&owner);CHKERRQ(ierr);
59469ce434fSBarry Smith     remote[i].rank  = owner;
59569ce434fSBarry Smith     remote[i].index = iremote[i] - layout->range[owner];
59669ce434fSBarry Smith   }
59769ce434fSBarry Smith   ierr = PetscSFSetGraph(sf,nroots,nleaves,ilocal,localmode,remote,PETSC_OWN_POINTER);CHKERRQ(ierr);
59869ce434fSBarry Smith   PetscFunctionReturn(0);
59969ce434fSBarry Smith }
60069ce434fSBarry Smith 
601