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> 54e5c89e4eSSatish Balay 5542218b76SBarry Smith /*@C 56811af0c4SBarry Smith PetscProcessPlacementView - display the MPI rank placement by core 57e5c89e4eSSatish Balay 585e71baefSBarry Smith Input Parameter: 59667f096bSBarry Smith . viewer - `PETSCVIEWERASCII` to display the results on 605e71baefSBarry Smith 6121fcc2ddSBarry Smith Level: intermediate 6221fcc2ddSBarry Smith 63811af0c4SBarry Smith Note: 64*a3b724e8SBarry Smith Requires that PETSc be installed with hwloc, for example using `--download-hwloc` 655e71baefSBarry Smith @*/ 66d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) 67d71ae5a4SJacob Faibussowitsch { 685e71baefSBarry Smith PetscBool isascii; 695e71baefSBarry Smith PetscMPIInt rank; 705e71baefSBarry Smith hwloc_bitmap_t set; 715e71baefSBarry Smith hwloc_topology_t topology; 725e71baefSBarry Smith 735e71baefSBarry Smith PetscFunctionBegin; 745e71baefSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 759566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 765f80ce2aSJacob Faibussowitsch PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported"); 775e71baefSBarry Smith 789566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); 795e71baefSBarry Smith hwloc_topology_init(&topology); 805e71baefSBarry Smith hwloc_topology_load(topology); 815e71baefSBarry Smith set = hwloc_bitmap_alloc(); 825e71baefSBarry Smith 83792fecdfSBarry Smith PetscCallExternal(hwloc_get_proc_cpubind, topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 849566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 859566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %d coreid %d\n", rank, getpid(), hwloc_bitmap_first(set))); 869566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 875e71baefSBarry Smith hwloc_bitmap_free(set); 885e71baefSBarry Smith hwloc_topology_destroy(topology); 893ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 905e71baefSBarry Smith } 915e71baefSBarry Smith #endif 92