Actual source code: ex16.c
1: /*$Id: ex16.c,v 1.12 2001/08/07 03:04:42 balay Exp $*/
3: static char help[] = "Tests VecPack routines.nn";
5: #include petscda.h
6: #include petscpf.h
8: int main(int argc,char **argv)
9: {
10: int ierr,nredundant1 = 5,nredundant2 = 2,rank,i,*ridx1,*ridx2,*lidx1,*lidx2,nlocal;
11: PetscScalar *redundant1,*redundant2;
12: VecPack packer;
13: Vec global,local1,local2;
14: PF pf;
15: DA da1,da2;
16: PetscViewer sviewer;
18: PetscInitialize(&argc,&argv,(char*)0,help);
19: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
21: VecPackCreate(PETSC_COMM_WORLD,&packer);
23: PetscMalloc(nredundant1*sizeof(PetscScalar),&redundant1);
24: VecPackAddArray(packer,nredundant1);
26: DACreate1d(PETSC_COMM_WORLD,DA_NONPERIODIC,8,1,1,PETSC_NULL,&da1);
27: DACreateLocalVector(da1,&local1);
28: VecPackAddDA(packer,da1);
30: PetscMalloc(nredundant2*sizeof(PetscScalar),&redundant2);
31: VecPackAddArray(packer,nredundant2);
33: DACreate1d(PETSC_COMM_WORLD,DA_NONPERIODIC,6,1,1,PETSC_NULL,&da2);
34: DACreateLocalVector(da2,&local2);
35: VecPackAddDA(packer,da2);
37: VecPackCreateGlobalVector(packer,&global);
38: PFCreate(PETSC_COMM_WORLD,1,1,&pf);
39: PFSetType(pf,PFIDENTITY,PETSC_NULL);
40: PFApplyVec(pf,PETSC_NULL,global);
41: PFDestroy(pf);
42: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
44: VecPackScatter(packer,global,redundant1,local1,redundant2,local2);
45: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] My part of redundant1 arrayn",rank);
46: PetscScalarView(nredundant1,redundant1,PETSC_VIEWER_STDOUT_WORLD);
47: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] My part of da1 vectorn",rank);
48: PetscViewerGetSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);
49: VecView(local1,sviewer);
50: PetscViewerRestoreSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);
51: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] My part of redundant2 arrayn",rank);
52: PetscScalarView(nredundant2,redundant2,PETSC_VIEWER_STDOUT_WORLD);
53: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] My part of da2 vectorn",rank);
54: PetscViewerGetSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);
55: VecView(local2,sviewer);
56: PetscViewerRestoreSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);
58: for (i=0; i<nredundant1; i++) redundant1[i] = (rank+2)*i;
59: for (i=0; i<nredundant2; i++) redundant2[i] = (rank+10)*i;
61: VecPackGather(packer,global,redundant1,local1,redundant2,local2);
62: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
64: /* get the global numbering for each subvector/array element */
65: VecPackGetGlobalIndices(packer,&ridx1,&lidx1,&ridx2,&lidx2);
66:
67: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] Global numbering of redundant1 arrayn",rank);
68: PetscIntView(nredundant1,ridx1,PETSC_VIEWER_STDOUT_WORLD);
69: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] Global numbering of local1 vectorn",rank);
70: VecGetSize(local1,&nlocal);
71: PetscIntView(nlocal,lidx1,PETSC_VIEWER_STDOUT_WORLD);
72: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] Global numbering of redundant2 arrayn",rank);
73: PetscIntView(nredundant2,ridx2,PETSC_VIEWER_STDOUT_WORLD);
74: PetscViewerASCIISynchronizedPrintf(PETSC_VIEWER_STDOUT_WORLD,"[%d] Global numbering of local2 vectorn",rank);
75: VecGetSize(local2,&nlocal);
76: PetscIntView(nlocal,lidx2,PETSC_VIEWER_STDOUT_WORLD);
77:
78: PetscFree(ridx1);
79: PetscFree(lidx1);
80: PetscFree(ridx2);
81: PetscFree(lidx2);
83: DADestroy(da1);
84: DADestroy(da2);
85: VecDestroy(local1);
86: VecDestroy(local2);
87: VecDestroy(global);
88: VecPackDestroy(packer);
89: PetscFree(redundant1);
90: PetscFree(redundant2);
91: PetscFinalize();
92: return 0;
93: }
94: