1e5c89e4eSSatish Balay /* 2e5c89e4eSSatish Balay We define the memory operations here. The reason we just do not use 3e5c89e4eSSatish Balay the standard memory routines in the PETSc code is that on some machines 4e5c89e4eSSatish Balay they are broken. 5e5c89e4eSSatish Balay 6e5c89e4eSSatish Balay */ 75f80ce2aSJacob Faibussowitsch #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 8778ae69aSToby Isaac #include <petscviewer.h> 9c6db04a5SJed Brown #include <../src/sys/utils/ftn-kernels/fcopy.h> 10e5c89e4eSSatish Balay 114610e317SSatish Balay /*@ 12e5c89e4eSSatish Balay PetscMemcmp - Compares two byte streams in memory. 13e5c89e4eSSatish Balay 14e5c89e4eSSatish Balay Not Collective 15e5c89e4eSSatish Balay 16e5c89e4eSSatish Balay Input Parameters: 17e5c89e4eSSatish Balay + str1 - Pointer to the first byte stream 18e5c89e4eSSatish Balay . str2 - Pointer to the second byte stream 19e5c89e4eSSatish Balay - len - The length of the byte stream 20e5c89e4eSSatish Balay (both str1 and str2 are assumed to be of length len) 21e5c89e4eSSatish Balay 222fe279fdSBarry Smith Output Parameter: 23811af0c4SBarry Smith . e - `PETSC_TRUE` if equal else `PETSC_FALSE`. 24e5c89e4eSSatish Balay 25e5c89e4eSSatish Balay Level: intermediate 26e5c89e4eSSatish Balay 27811af0c4SBarry Smith Notes: 28811af0c4SBarry Smith `PetscArraycmp()` is preferred 29811af0c4SBarry Smith 3035cb6cd3SPierre Jolivet This routine is analogous to `memcmp()` with additional error checking 31580bdb30SBarry Smith 3242747ad1SJacob Faibussowitsch .seealso: `PetscMemcpy()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 33db781477SPatrick Sanan `PetscArraymove()` 34e5c89e4eSSatish Balay @*/ 35d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscMemcmp(const void *str1, const void *str2, size_t len, PetscBool *e) 36d71ae5a4SJacob Faibussowitsch { 375f80ce2aSJacob Faibussowitsch if (!len) { 385f80ce2aSJacob Faibussowitsch // if e is a bad ptr I guess we just die here then? 395f80ce2aSJacob Faibussowitsch *e = PETSC_TRUE; 403ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 415f80ce2aSJacob Faibussowitsch } 42c3e24edfSBarry Smith 43e5c89e4eSSatish Balay PetscFunctionBegin; 444f572ea9SToby Isaac PetscAssertPointer(str1, 1); 454f572ea9SToby Isaac PetscAssertPointer(str2, 2); 464f572ea9SToby Isaac PetscAssertPointer(e, 4); 475f80ce2aSJacob Faibussowitsch *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE; 483ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 49e5c89e4eSSatish Balay } 50e5c89e4eSSatish Balay 515e71baefSBarry Smith #if defined(PETSC_HAVE_HWLOC) 525e71baefSBarry Smith #include <petsc/private/petscimpl.h> 535e71baefSBarry Smith #include <hwloc.h> 54*ffeef943SBarry Smith #endif 55e5c89e4eSSatish Balay 56*ffeef943SBarry Smith /*@ 57811af0c4SBarry Smith PetscProcessPlacementView - display the MPI rank placement by core 58e5c89e4eSSatish Balay 595e71baefSBarry Smith Input Parameter: 60667f096bSBarry Smith . viewer - `PETSCVIEWERASCII` to display the results on 615e71baefSBarry Smith 6221fcc2ddSBarry Smith Level: intermediate 6321fcc2ddSBarry Smith 64811af0c4SBarry Smith Note: 65a3b724e8SBarry Smith Requires that PETSc be installed with hwloc, for example using `--download-hwloc` 66*ffeef943SBarry Smith 67*ffeef943SBarry Smith .seealso: `PetscInitialize()` 685e71baefSBarry Smith @*/ 69d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) 70d71ae5a4SJacob Faibussowitsch { 71*ffeef943SBarry Smith #if defined(PETSC_HAVE_HWLOC) 725e71baefSBarry Smith PetscBool isascii; 735e71baefSBarry Smith PetscMPIInt rank; 745e71baefSBarry Smith hwloc_bitmap_t set; 755e71baefSBarry Smith hwloc_topology_t topology; 765e71baefSBarry Smith 775e71baefSBarry Smith PetscFunctionBegin; 785e71baefSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 799566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 805f80ce2aSJacob Faibussowitsch PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported"); 815e71baefSBarry Smith 829566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); 835e71baefSBarry Smith hwloc_topology_init(&topology); 845e71baefSBarry Smith hwloc_topology_load(topology); 855e71baefSBarry Smith set = hwloc_bitmap_alloc(); 865e71baefSBarry Smith 87792fecdfSBarry Smith PetscCallExternal(hwloc_get_proc_cpubind, topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 889566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 899566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %d coreid %d\n", rank, getpid(), hwloc_bitmap_first(set))); 909566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 915e71baefSBarry Smith hwloc_bitmap_free(set); 925e71baefSBarry Smith hwloc_topology_destroy(topology); 93*ffeef943SBarry Smith #else 94*ffeef943SBarry Smith PetscFunctionBegin; 95*ffeef943SBarry Smith SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Requires PETSc be configured with --with-hwloc or --download-hwloc"); 96*ffeef943SBarry Smith #endif 973ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 985e71baefSBarry Smith } 99