Actual source code: dagtona.c
1: /*
2: Tools to help solve the coarse grid problem redundantly.
3: Provides two scatter contexts that (1) map from the usual global vector
4: to all processors the entire vector in NATURAL numbering and (2)
5: from the entire vector on each processor in natural numbering extracts
6: out this processors piece in GLOBAL numbering
7: */
9: #include src/dm/da/daimpl.h
13: /*@
14: DAGlobalToNaturalAllCreate - Creates a scatter context that maps from the
15: global vector the entire vector to each processor in natural numbering
17: Collective on DA
19: Input Parameter:
20: . da - the distributed array context
22: Output Parameter:
23: . scatter - the scatter context
25: Level: advanced
27: .keywords: distributed array, global to local, begin, coarse problem
29: .seealso: DAGlobalToNaturalEnd(), DALocalToGlobal(), DACreate2d(),
30: DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DACreateNaturalVector()
31: @*/
32: PetscErrorCode DAGlobalToNaturalAllCreate(DA da,VecScatter *scatter)
33: {
35: PetscInt N;
36: IS from,to;
37: Vec tmplocal,global;
38: AO ao;
43: DAGetAO(da,&ao);
45: /* create the scatter context */
46: ISCreateStride(da->comm,da->Nlocal,0,1,&to);
47: AOPetscToApplicationIS(ao,to);
48: ISCreateStride(da->comm,da->Nlocal,0,1,&from);
49: MPI_Allreduce(&da->Nlocal,&N,1,MPIU_INT,MPI_SUM,da->comm);
50: VecCreateSeqWithArray(PETSC_COMM_SELF,N,0,&tmplocal);
51: VecCreateMPIWithArray(da->comm,da->Nlocal,PETSC_DETERMINE,0,&global);
52: VecScatterCreate(global,from,tmplocal,to,scatter);
53: VecDestroy(tmplocal);
54: VecDestroy(global);
55: ISDestroy(from);
56: ISDestroy(to);
57: return(0);
58: }
62: /*@
63: DANaturalAllToGlobalCreate - Creates a scatter context that maps from a copy
64: of the entire vector on each processor to its local part in the global vector.
66: Collective on DA
68: Input Parameter:
69: . da - the distributed array context
71: Output Parameter:
72: . scatter - the scatter context
74: Level: advanced
76: .keywords: distributed array, global to local, begin, coarse problem
78: .seealso: DAGlobalToNaturalEnd(), DALocalToGlobal(), DACreate2d(),
79: DAGlobalToLocalBegin(), DAGlobalToLocalEnd(), DACreateNaturalVector()
80: @*/
81: PetscErrorCode DANaturalAllToGlobalCreate(DA da,VecScatter *scatter)
82: {
84: PetscInt M,m = da->Nlocal,start;
85: IS from,to;
86: Vec tmplocal,global;
87: AO ao;
92: DAGetAO(da,&ao);
94: /* create the scatter context */
95: MPI_Allreduce(&m,&M,1,MPIU_INT,MPI_SUM,da->comm);
96: VecCreateMPIWithArray(da->comm,m,PETSC_DETERMINE,0,&global);
97: VecGetOwnershipRange(global,&start,PETSC_NULL);
98: ISCreateStride(da->comm,m,start,1,&from);
99: AOPetscToApplicationIS(ao,from);
100: ISCreateStride(da->comm,m,start,1,&to);
101: VecCreateSeqWithArray(PETSC_COMM_SELF,M,0,&tmplocal);
102: VecScatterCreate(tmplocal,from,global,to,scatter);
103: VecDestroy(tmplocal);
104: VecDestroy(global);
105: ISDestroy(from);
106: ISDestroy(to);
107: return(0);
108: }