Actual source code: ex33.c

  1: static char help[] = "Tests PetscPartitioner.\n\n";

  3: #include <petscpartitioner.h>

  5: int main(int argc, char **argv)
  6: {
  7:   PetscPartitioner p;
  8:   PetscSection     partSection, vertexSection = NULL, targetSection = NULL;
  9:   IS               partition,is;
 10:   PetscMPIInt      size,rank;
 11:   PetscInt         nparts,i;
 12:   PetscInt         nv = 4;
 13:   PetscInt         vv[5] = {0,2,4,6,8};
 14:   PetscInt         vadj[8] = {3,1,0,2,1,3,2,0};
 15:   PetscBool        sequential;
 16:   PetscBool        vwgts = PETSC_FALSE;
 17:   PetscBool        pwgts = PETSC_FALSE;

 19:   PetscInitialize(&argc, &argv, NULL, help);
 20:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 21:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 22:   nparts = size;
 23:   PetscOptionsGetInt(NULL,NULL,"-nparts",&nparts,NULL);
 24:   PetscOptionsGetBool(NULL,NULL,"-vwgts",&vwgts,NULL);
 25:   PetscOptionsGetBool(NULL,NULL,"-pwgts",&pwgts,NULL);

 27:   /* create PetscPartitioner */
 28:   PetscPartitionerCreate(PETSC_COMM_WORLD,&p);
 29:   PetscPartitionerSetType(p,PETSCPARTITIONERSIMPLE);
 30:   PetscPartitionerSetFromOptions(p);

 32:   /* create partition section */
 33:   PetscSectionCreate(PETSC_COMM_WORLD,&partSection);

 35:   if (vwgts) { /* create vertex weights section */
 36:     PetscSectionCreate(PETSC_COMM_WORLD,&vertexSection);
 37:     PetscSectionSetChart(vertexSection,0,nv);
 38:     for (i = 0; i< nv; i++) PetscSectionSetDof(vertexSection,i,1);
 39:     PetscSectionSetUp(vertexSection);
 40:   }

 42:   if (pwgts) { /* create partition weights section */
 43:     PetscSectionCreate(PETSC_COMM_WORLD,&targetSection);
 44:     PetscSectionSetChart(targetSection,0,nparts);
 45:     for (i = 0; i< nparts; i++) PetscSectionSetDof(targetSection,i,1);
 46:     PetscSectionSetUp(targetSection);
 47:   }

 49: #if defined(PETSC_USE_LOG)
 50:   { /* Test logging */
 51:     PetscLogEvent event;

 53:     PetscLogEventRegister("MyPartitionerEvent",PETSCPARTITIONER_CLASSID,&event);
 54:     { /* PetscLogEventExcludeClass is broken, new events are not deactivated */
 55:       char      logList[256];
 56:       PetscBool opt,pkg;

 58:       PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
 59:       if (opt) {
 60:         PetscStrInList("partitioner",logList,',',&pkg);
 61:         if (pkg) PetscLogEventExcludeClass(PETSCPARTITIONER_CLASSID);
 62:       }
 63:     }
 64:     PetscLogEventBegin(event,p,NULL,NULL,NULL);
 65:     PetscLogEventEnd(event,p,NULL,NULL,NULL);
 66:   }
 67: #endif

 69:   /* test setup and reset */
 70:   PetscPartitionerSetUp(p);
 71:   PetscPartitionerReset(p);

 73:   /* test partitioning an empty graph */
 74:   PetscPartitionerPartition(p,nparts,0,NULL,NULL,vertexSection,targetSection,partSection,&partition);
 75:   PetscObjectSetName((PetscObject)partSection,"NULL SECTION");
 76:   PetscSectionView(partSection,NULL);
 77:   ISOnComm(partition,PETSC_COMM_WORLD,PETSC_USE_POINTER,&is);
 78:   PetscObjectSetName((PetscObject)is,"NULL PARTITION");
 79:   ISView(is,NULL);
 80:   ISDestroy(&is);
 81:   ISDestroy(&partition);

 83:   /* test view from options */
 84:   PetscPartitionerViewFromOptions(p,NULL,"-part_view");

 86:   /* test partitioning a graph on one process only (not main) */
 87:   if (rank == size - 1) {
 88:     PetscPartitionerPartition(p,nparts,nv,vv,vadj,vertexSection,targetSection,partSection,&partition);
 89:   } else {
 90:     PetscPartitionerPartition(p,nparts,0,NULL,NULL,vertexSection,targetSection,partSection,&partition);
 91:   }
 92:   PetscObjectSetName((PetscObject)partSection,"SEQ SECTION");
 93:   PetscSectionView(partSection,NULL);
 94:   ISOnComm(partition,PETSC_COMM_WORLD,PETSC_USE_POINTER,&is);
 95:   PetscObjectSetName((PetscObject)is,"SEQ PARTITION");
 96:   ISView(is,NULL);
 97:   ISDestroy(&is);
 98:   ISDestroy(&partition);

100:   PetscObjectTypeCompareAny((PetscObject)p,&sequential,PETSCPARTITIONERCHACO,NULL);
101:   if (sequential) goto finally;

103:   /* test partitioning a graph on a subset of the processess only */
104:   if (rank%2) {
105:     PetscPartitionerPartition(p,nparts,0,NULL,NULL,NULL,targetSection,partSection,&partition);
106:   } else {
107:     PetscInt i,totv = nv*((size+1)/2),*pvadj;

109:     PetscMalloc1(2*nv,&pvadj);
110:     for (i = 0; i < nv; i++) {
111:       pvadj[2*i]   = (nv*(rank/2) + totv + i - 1)%totv;
112:       pvadj[2*i+1] = (nv*(rank/2) + totv + i + 1)%totv;
113:     }
114:     PetscPartitionerPartition(p,nparts,nv,vv,pvadj,NULL,targetSection,partSection,&partition);
115:     PetscFree(pvadj);
116:   }
117:   PetscObjectSetName((PetscObject)partSection,"PARVOID SECTION");
118:   PetscSectionView(partSection,NULL);
119:   ISOnComm(partition,PETSC_COMM_WORLD,PETSC_USE_POINTER,&is);
120:   PetscObjectSetName((PetscObject)is,"PARVOID PARTITION");
121:   ISView(is,NULL);
122:   ISDestroy(&is);
123:   ISDestroy(&partition);

125: finally:
126:   PetscSectionDestroy(&partSection);
127:   PetscSectionDestroy(&vertexSection);
128:   PetscSectionDestroy(&targetSection);
129:   PetscPartitionerDestroy(&p);
130:   PetscFinalize();
131:   return 0;
132: }

134: /*TEST

136:   test:
137:     suffix: default

139:   testset:
140:     requires: defined(PETSC_USE_LOG)
141:     args: -petscpartitioner_type simple -log_summary
142:     filter: grep MyPartitionerEvent | cut -d " " -f 1
143:     test:
144:        suffix: log_include
145:     test:
146:       suffix: log_exclude
147:       args: -log_exclude partitioner

149:   test:
150:     suffix: simple
151:     nsize: {{1 2 3}separate output}
152:     args: -nparts {{1 2 3}separate output} -pwgts {{false true}separate output} -petscpartitioner_type simple -petscpartitioner_view

154:   test:
155:     suffix: shell
156:     nsize: {{1 2 3}separate output}
157:     args: -nparts {{1 2 3}separate output} -petscpartitioner_type shell -petscpartitioner_shell_random -petscpartitioner_view

159:   test:
160:     suffix: gather
161:     nsize: {{1 2 3}separate output}
162:     args: -nparts {{1 2 3}separate output} -petscpartitioner_type gather -petscpartitioner_view -petscpartitioner_view_graph

164:   test:
165:     requires: parmetis
166:     suffix: parmetis
167:     nsize: {{1 2 3}separate output}
168:     args: -nparts {{1 2 3}separate output} -pwgts {{false true}} -vwgts {{false true}}
169:     args: -petscpartitioner_type parmetis -petscpartitioner_view -petscpartitioner_view_graph

171:   test:
172:     requires: parmetis
173:     suffix: parmetis_type
174:     nsize: {{1 2}}
175:     args: -petscpartitioner_type parmetis -part_view
176:     args: -petscpartitioner_parmetis_type {{kway rb}separate output}
177:     filter: grep "ParMetis type"

179:   test:
180:     requires: ptscotch
181:     suffix: ptscotch
182:     nsize: {{1 2 3}separate output}
183:     args: -nparts {{1 2 3}separate output} -pwgts {{false true}separate output} -vwgts {{false true}}
184:     args: -petscpartitioner_type ptscotch -petscpartitioner_view -petscpartitioner_view_graph

186:   test:
187:     requires: ptscotch
188:     suffix: ptscotch_strategy
189:     nsize: {{1 2}}
190:     args: -petscpartitioner_type ptscotch -part_view
191:     args: -petscpartitioner_ptscotch_strategy {{DEFAULT QUALITY SPEED BALANCE SAFETY SCALABILITY RECURSIVE REMAP}separate output}
192:     filter: grep "partitioning strategy"

194:   test:
195:     requires: chaco
196:     suffix: chaco
197:     nsize: {{1 2 3}separate output}
198:     args: -nparts {{1}separate output} -petscpartitioner_type chaco -petscpartitioner_view -petscpartitioner_view_graph

200:   test:
201:     TODO: non reproducible (uses C stdlib rand())
202:     requires: chaco
203:     suffix: chaco
204:     nsize: {{1 2 3}separate output}
205:     args: -nparts {{2 3}separate output} -petscpartitioner_type chaco -petscpartitioner_view -petscpartitioner_view_graph

207: TEST*/