Lines Matching refs:mapping

126     Creates the global mapping information in the ISLocalToGlobalMapping structure
128 If the user has not selected how to handle the global to local mapping then use HASH for "large" problems
130 static PetscErrorCode ISGlobalToLocalMappingSetUp(ISLocalToGlobalMapping mapping)
132 PetscInt i, *idx = mapping->indices, n = mapping->n, end, start;
135 if (mapping->data) PetscFunctionReturn(PETSC_SUCCESS);
148 mapping->globalstart = start;
149 mapping->globalend = end;
150 if (!((PetscObject)mapping)->type_name) {
152 PetscCall(ISLocalToGlobalMappingSetType(mapping, ISLOCALTOGLOBALMAPPINGHASH));
154 PetscCall(ISLocalToGlobalMappingSetType(mapping, ISLOCALTOGLOBALMAPPINGBASIC));
157 PetscTryTypeMethod(mapping, globaltolocalmappingsetup);
161 static PetscErrorCode ISGlobalToLocalMappingSetUp_Basic(ISLocalToGlobalMapping mapping)
163 PetscInt i, *idx = mapping->indices, n = mapping->n, end, start, *globals;
167 start = mapping->globalstart;
168 end = mapping->globalend;
177 mapping->data = (void *)map;
181 static PetscErrorCode ISGlobalToLocalMappingSetUp_Hash(ISLocalToGlobalMapping mapping)
183 PetscInt i, *idx = mapping->indices, n = mapping->n;
193 mapping->data = (void *)map;
197 static PetscErrorCode ISLocalToGlobalMappingDestroy_Basic(ISLocalToGlobalMapping mapping)
199 ISLocalToGlobalMapping_Basic *map = (ISLocalToGlobalMapping_Basic *)mapping->data;
204 PetscCall(PetscFree(mapping->data));
208 static PetscErrorCode ISLocalToGlobalMappingDestroy_Hash(ISLocalToGlobalMapping mapping)
210 ISLocalToGlobalMapping_Hash *map = (ISLocalToGlobalMapping_Hash *)mapping->data;
215 PetscCall(PetscFree(mapping->data));
219 static PetscErrorCode ISLocalToGlobalMappingResetBlockInfo_Private(ISLocalToGlobalMapping mapping)
222 PetscCall(PetscFree(mapping->info_procs));
223 PetscCall(PetscFree(mapping->info_numprocs));
224 if (mapping->info_indices) {
225 for (PetscInt i = 0; i < mapping->info_nproc; i++) PetscCall(PetscFree(mapping->info_indices[i]));
226 PetscCall(PetscFree(mapping->info_indices));
228 if (mapping->info_nodei) PetscCall(PetscFree(mapping->info_nodei[0]));
229 PetscCall(PetscFree2(mapping->info_nodec, mapping->info_nodei));
230 PetscCall(PetscSFDestroy(&mapping->multileaves_sf));
236 #define GTOLBS mapping->bs
256 #define GTOLBS mapping->bs
274 ISLocalToGlobalMappingDuplicate - Duplicates the local to global mapping object
279 . ltog - local to global mapping
282 . nltog - the duplicated local to global mapping
301 ISLocalToGlobalMappingGetSize - Gets the local size of a local to global mapping
306 . mapping - local to global mapping
309 . n - the number of entries in the local mapping, `ISLocalToGlobalMappingGetIndices()` returns an array of this length
315 PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping mapping, PetscInt *n)
318 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
320 *n = mapping->bs * mapping->n;
330 + A - the local to global mapping object
350 ISLocalToGlobalMappingView - View a local to global mapping
355 + mapping - local to global mapping
362 PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping mapping, PetscViewer viewer)
368 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
369 if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)mapping), &viewer));
379 const char *name = ((PetscObject)mapping)->name;
383 PetscCall(ISLocalToGlobalMappingGetIndices(mapping, &idxs));
384 PetscCall(ISCreateGeneral(PetscObjectComm((PetscObject)viewer), mapping->n * mapping->bs, idxs, PETSC_USE_POINTER, &is));
387 PetscCall(ISLocalToGlobalMappingRestoreIndices(mapping, &idxs));
392 PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)mapping), &rank));
393 PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)mapping, viewer));
395 for (PetscInt i = 0; i < mapping->n; i++) {
396 PetscInt bs = mapping->bs, g = mapping->indices[i];
414 tr[1] = mapping->bs;
417 PetscCall(PetscViewerBinaryWriteAll(viewer, &mapping->n, 1, PETSC_DETERMINE, PETSC_DETERMINE, PETSC_INT));
420 PetscCall(PetscViewerBinaryWriteAll(viewer, mapping->indices, mapping->n, PETSC_DETERMINE, PETSC_DETERMINE, PETSC_INT));
426 ISLocalToGlobalMappingLoad - Loads a local-to-global mapping that has been stored in binary format.
431 + mapping - the newly loaded map, this needs to have been created with `ISLocalToGlobalMappingCreate()` or some related function before a call to `ISLocalToGlobalMappingLoad()`
438 PetscErrorCode ISLocalToGlobalMappingLoad(ISLocalToGlobalMapping mapping, PetscViewer viewer)
443 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
449 PetscCall(ISLocalToGlobalMappingResetBlockInfo_Private(mapping));
457 PetscInt tr[3], nold = mapping->n, *sizes, nmaps = PETSC_DECIDE, st = 0;
462 mapping->bs = tr[1];
469 mapping->n = 0;
470 for (PetscInt i = st; i < st + nmaps; i++) mapping->n += sizes[i];
473 if (nold != mapping->n) {
474 if (mapping->dealloc_indices) PetscCall(PetscFree(mapping->indices));
475 mapping->indices = NULL;
480 if (mapping->n && !mapping->indices) {
481 PetscCall(PetscMalloc1(mapping->n, &mapping->indices));
482 mapping->dealloc_indices = PETSC_TRUE;
484 PetscCall(PetscViewerBinaryReadAll(viewer, mapping->indices, mapping->n, PETSC_DETERMINE, PETSC_DETERMINE, PETSC_INT));
489 ISLocalToGlobalMappingCreateIS - Creates a mapping between a local (0 to n)
498 . mapping - new mapping data structure
503 the block size of the `IS` determines the block size of the mapping
507 PetscErrorCode ISLocalToGlobalMappingCreateIS(IS is, ISLocalToGlobalMapping *mapping)
516 PetscAssertPointer(mapping, 2);
523 PetscCall(ISLocalToGlobalMappingCreate(comm, 1, n, indices, PETSC_COPY_VALUES, mapping));
528 PetscCall(ISLocalToGlobalMappingCreate(comm, bs, n / bs, indices, PETSC_COPY_VALUES, mapping));
535 ISLocalToGlobalMappingCreateSF - Creates a mapping between a local (0 to n) ordering and a global parallel ordering induced by a star forest.
540 + sf - star forest mapping contiguous local indices to (rank, offset)
544 . mapping - new mapping data structure
553 PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF sf, PetscInt start, ISLocalToGlobalMapping *mapping)
560 PetscAssertPointer(mapping, 3);
575 PetscCall(ISLocalToGlobalMappingCreate(comm, 1, maxlocal, ltog, PETSC_OWN_POINTER, mapping));
581 ISLocalToGlobalMappingSetBlockSize - Sets the blocksize of the mapping
586 + mapping - mapping data structure
593 PetscErrorCode ISLocalToGlobalMappingSetBlockSize(ISLocalToGlobalMapping mapping, PetscInt bs)
600 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
602 if (bs == mapping->bs) PetscFunctionReturn(PETSC_SUCCESS);
603 on = mapping->n;
604 obs = mapping->bs;
605 oid = mapping->indices;
610 PetscCall(ISLocalToGlobalMappingGetIndices(mapping, &oid));
628 PetscCall(ISLocalToGlobalMappingRestoreIndices(mapping, &oid));
630 mapping->n = nn;
631 mapping->bs = bs;
632 PetscCall(PetscFree(mapping->indices));
633 mapping->indices = nid;
634 mapping->globalstart = 0;
635 mapping->globalend = 0;
638 PetscCall(ISLocalToGlobalMappingResetBlockInfo_Private(mapping));
639 PetscTryTypeMethod(mapping, destroy);
644 ISLocalToGlobalMappingGetBlockSize - Gets the blocksize of the mapping
650 . mapping - mapping data structure
659 PetscErrorCode ISLocalToGlobalMappingGetBlockSize(ISLocalToGlobalMapping mapping, PetscInt *bs)
662 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
663 *bs = mapping->bs;
668 ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n)
681 . mapping - new mapping data structure
699 PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm comm, PetscInt bs, PetscInt n, const PetscInt indices[], PetscCopyMode mode, ISLocalToGlobalMapping *mapping)
705 PetscAssertPointer(mapping, 6);
707 *mapping = NULL;
710 PetscCall(PetscHeaderCreate(*mapping, IS_LTOGM_CLASSID, "ISLocalToGlobalMapping", "Local to global mapping", "IS", comm, ISLocalToGlobalMappingDestroy, ISLocalToGlobalMappingView));
711 (*mapping)->n = n;
712 (*mapping)->bs = bs;
716 (*mapping)->indices = in;
717 (*mapping)->dealloc_indices = PETSC_TRUE;
719 (*mapping)->indices = (PetscInt *)indices;
720 (*mapping)->dealloc_indices = PETSC_TRUE;
722 (*mapping)->indices = (PetscInt *)indices;
730 ISLocalToGlobalMappingSetFromOptions - Set mapping options from the options database.
735 . mapping - mapping data structure
746 PetscErrorCode ISLocalToGlobalMappingSetFromOptions(ISLocalToGlobalMapping mapping)
753 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
755 PetscObjectOptionsBegin((PetscObject)mapping);
756 PetscCall(PetscOptionsFList("-islocaltoglobalmapping_type", "ISLocalToGlobalMapping method", "ISLocalToGlobalMappingSetType", ISLocalToGlobalMappingList, ((PetscObject)mapping)->type_name ? ((PetscObject)mapping)->type_name : defaulttype, type, 256, &flg));
757 if (flg) PetscCall(ISLocalToGlobalMappingSetType(mapping, type));
763 ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n)
769 . mapping - mapping data structure
775 PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping *mapping)
778 if (!*mapping) PetscFunctionReturn(PETSC_SUCCESS);
779 PetscValidHeaderSpecific(*mapping, IS_LTOGM_CLASSID, 1);
780 if (--((PetscObject)*mapping)->refct > 0) {
781 *mapping = NULL;
784 if ((*mapping)->dealloc_indices) PetscCall(PetscFree((*mapping)->indices));
785 PetscCall(ISLocalToGlobalMappingResetBlockInfo_Private(*mapping));
786 PetscTryTypeMethod(*mapping, destroy);
787 PetscCall(PetscHeaderDestroy(mapping));
799 + mapping - mapping between local and global numbering
813 PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis)
819 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
827 PetscCall(ISLocalToGlobalMappingApply(mapping, n, idxin, idxout));
841 + mapping - the local to global mapping context
857 PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping, PetscInt N, const PetscInt in[], PetscInt out[])
862 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
863 bs = mapping->bs;
864 Nmax = bs * mapping->n;
866 const PetscInt *idx = mapping->indices;
876 const PetscInt *idx = mapping->indices;
895 + mapping - the local to global mapping context
903 If the index values are {0,1,6,7} set with a call to `ISLocalToGlobalMappingCreate`(`PETSC_COMM_SELF`,2,2,{0,3}) then the mapping applied to 0
904 (the first block) would produce 0 and the mapping applied to 1 (the second block) would produce 3.
915 PetscErrorCode ISLocalToGlobalMappingApplyBlock(ISLocalToGlobalMapping mapping, PetscInt N, const PetscInt in[], PetscInt out[])
921 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
922 Nmax = mapping->n;
923 idx = mapping->indices;
942 + mapping - mapping between local and global numbering
973 PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping mapping, ISGlobalToLocalMappingMode type, PetscInt n, const PetscInt idx[], PetscInt *nout, PetscInt idxout[])
976 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
977 if (!mapping->data) PetscCall(ISGlobalToLocalMappingSetUp(mapping));
978 PetscUseTypeMethod(mapping, globaltolocalmappingapply, type, n, idx, nout, idxout);
990 + mapping - mapping between local and global numbering
1008 PetscErrorCode ISGlobalToLocalMappingApplyIS(ISLocalToGlobalMapping mapping, ISGlobalToLocalMappingMode type, IS is, IS *newis)
1014 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1023 PetscCall(ISGlobalToLocalMappingApply(mapping, type, n, idxin, &nout, NULL));
1026 PetscCall(ISGlobalToLocalMappingApply(mapping, type, n, idxin, &nout, idxout));
1043 + mapping - mapping between local and global numbering
1074 PetscErrorCode ISGlobalToLocalMappingApplyBlock(ISLocalToGlobalMapping mapping, ISGlobalToLocalMappingMode type, PetscInt n, const PetscInt idx[], PetscInt *nout, PetscInt idxout[])
1077 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1078 if (!mapping->data) PetscCall(ISGlobalToLocalMappingSetUp(mapping));
1079 PetscUseTypeMethod(mapping, globaltolocalmappingapplyblock, type, n, idx, nout, idxout);
1089 . mapping - the mapping from local to global indexing
1102 PetscErrorCode ISLocalToGlobalMappingGetBlockInfo(ISLocalToGlobalMapping mapping, PetscInt *nproc, PetscInt *procs[], PetscInt *numprocs[], PetscInt **indices[])
1105 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1106 PetscCall(ISLocalToGlobalMappingSetUpBlockInfo_Private(mapping));
1107 if (nproc) *nproc = mapping->info_nproc;
1108 if (procs) *procs = mapping->info_procs;
1109 if (numprocs) *numprocs = mapping->info_numprocs;
1110 if (indices) *indices = mapping->info_indices;
1120 . mapping - the mapping from local to global indexing
1133 cannot be inferred in the general case, unless the mapping is locally one-to-one on each process.
1138 PetscErrorCode ISLocalToGlobalMappingGetBlockNodeInfo(ISLocalToGlobalMapping mapping, PetscInt *n, PetscInt *n_procs[], PetscInt **procs[])
1141 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1142 PetscCall(ISLocalToGlobalMappingSetUpBlockInfo_Private(mapping));
1143 if (n) *n = mapping->n;
1144 if (n_procs) *n_procs = mapping->info_nodec;
1145 if (procs) *procs = mapping->info_nodei;
1155 + mapping - the mapping from local to global indexing
1165 PetscErrorCode ISLocalToGlobalMappingRestoreBlockNodeInfo(ISLocalToGlobalMapping mapping, PetscInt *n, PetscInt *n_procs[], PetscInt **procs[])
1168 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1181 . mapping - the mapping from local to global indexing
1190 For example, suppose a mapping with two processes has been created with
1209 PetscErrorCode ISLocalToGlobalMappingGetBlockMultiLeavesSF(ISLocalToGlobalMapping mapping, PetscSF *mlsf)
1212 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1214 PetscCall(ISLocalToGlobalMappingSetUpBlockInfo_Private(mapping));
1215 *mlsf = mapping->multileaves_sf;
1219 static PetscErrorCode ISLocalToGlobalMappingSetUpBlockInfo_Private(ISLocalToGlobalMapping mapping)
1235 if (mapping->multileaves_sf) PetscFunctionReturn(PETSC_SUCCESS);
1236 PetscCall(PetscObjectGetComm((PetscObject)mapping, &comm));
1240 /* Get mapping indices */
1241 PetscCall(ISLocalToGlobalMappingGetBlockSize(mapping, &bs));
1242 PetscCall(ISLocalToGlobalMappingGetBlockIndices(mapping, &gidxs));
1243 PetscCall(ISLocalToGlobalMappingGetSize(mapping, &nleaves));
1315 PetscCall(PetscHMapIGetSize(neighs, &mapping->info_nproc));
1316 PetscCall(PetscMalloc1(mapping->info_nproc, &mapping->info_procs));
1317 PetscCall(PetscHMapIGetKeys(neighs, (i = 0, &i), mapping->info_procs));
1318 for (i = 0; i < mapping->info_nproc; i++) { /* put info for self first */
1319 if (mapping->info_procs[i] == rank) {
1320 PetscInt newr = mapping->info_procs[0];
1322 mapping->info_procs[0] = rank;
1323 mapping->info_procs[i] = newr;
1327 if (mapping->info_nproc) PetscCall(PetscSortInt(mapping->info_nproc - 1, mapping->info_procs + 1));
1331 PetscCall(PetscMalloc1(mapping->info_nproc, &mapping->info_numprocs));
1332 PetscCall(PetscMalloc1(mapping->info_nproc, &mapping->info_indices));
1333 for (i = 0; i < mapping->info_nproc; i++) mapping->info_indices[i] = NULL;
1337 for (p = 0; p < mapping->info_nproc; p++) {
1338 PetscInt *tmp, trank = mapping->info_procs[p];
1359 mapping->info_indices[p] = tmp;
1360 mapping->info_numprocs[p] = m;
1364 PetscCall(PetscMalloc2(nleaves, &mapping->info_nodec, nleaves + 1, &mapping->info_nodei));
1365 PetscCall(PetscArraycpy(mapping->info_nodec, leafrd, nleaves));
1366 PetscCall(PetscMalloc1(newnleaves, &mapping->info_nodei[0]));
1367 for (i = 0; i < nleaves - 1; i++) mapping->info_nodei[i + 1] = mapping->info_nodei[i] + mapping->info_nodec[i];
1368 PetscCall(PetscArraycpy(mapping->info_nodei[0], newleafdata, newnleaves));
1373 PetscCall(PetscSFCompose(imsf, sf2, &mapping->multileaves_sf));
1378 PetscCall(ISLocalToGlobalMappingRestoreBlockIndices(mapping, &gidxs));
1392 + mapping - the mapping from local to global indexing
1403 PetscErrorCode ISLocalToGlobalMappingRestoreBlockInfo(ISLocalToGlobalMapping mapping, PetscInt *nproc, PetscInt *procs[], PetscInt *numprocs[], PetscInt **indices[])
1406 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1420 . mapping - the mapping from local to global indexing
1441 PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping mapping, PetscInt *nproc, PetscInt *procs[], PetscInt *numprocs[], PetscInt **indices[])
1446 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1447 bs = mapping->bs;
1448 PetscCall(ISLocalToGlobalMappingGetBlockInfo(mapping, &n, &bprocs, &bnumprocs, &bindices));
1478 + mapping - the mapping from local to global indexing
1489 PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping mapping, PetscInt *nproc, PetscInt *procs[], PetscInt *numprocs[], PetscInt **indices[])
1492 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1493 if (mapping->bs > 1) {
1510 . mapping - the mapping from local to global indexing
1525 PetscErrorCode ISLocalToGlobalMappingGetNodeInfo(ISLocalToGlobalMapping mapping, PetscInt *n, PetscInt *n_procs[], PetscInt **procs[])
1530 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1531 bs = mapping->bs;
1532 PetscCall(ISLocalToGlobalMappingGetBlockNodeInfo(mapping, &bn, &bn_procs, &bprocs));
1573 + mapping - the mapping from local to global indexing
1583 PetscErrorCode ISLocalToGlobalMappingRestoreNodeInfo(ISLocalToGlobalMapping mapping, PetscInt *n, PetscInt *n_procs[], PetscInt **procs[])
1586 PetscValidHeaderSpecific(mapping, IS_LTOGM_CLASSID, 1);
1587 if (mapping->bs > 1) {
1594 PetscCall(ISLocalToGlobalMappingRestoreBlockNodeInfo(mapping, n, n_procs, procs));
1604 . ltog - local to global mapping
1644 + ltog - local to global mapping
1667 . ltog - local to global mapping
1692 + ltog - local to global mapping
1710 ISLocalToGlobalMappingConcatenate - Create a new mapping that concatenates a list of mappings
1715 + comm - communicator for the new mapping, must contain the communicator of every mapping to concatenate
1720 . ltogcat - new mapping
1725 This currently always returns a mapping with block size of 1
1728 If all the input mapping have the same block size we could easily handle that as a special case
1768 This stores all the mapping information on each MPI rank.
1807 ISLocalToGlobalMappingRegister - Registers a method for applying a global to local mapping with an `ISLocalToGlobalMapping`
1820 Then, your mapping can be chosen with the procedural interface via
1925 ISLocalToGlobalMappingRegisterAll - Registers all of the local to global mapping components in the `IS` package.