1 2 /* 3 We define the memory operations here. The reason we just do not use 4 the standard memory routines in the PETSc code is that on some machines 5 they are broken. 6 7 */ 8 #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 9 #include <petscbt.h> 10 #include <../src/sys/utils/ftn-kernels/fcopy.h> 11 12 /*@ 13 PetscMemcmp - Compares two byte streams in memory. 14 15 Not Collective 16 17 Input Parameters: 18 + str1 - Pointer to the first byte stream 19 . str2 - Pointer to the second byte stream 20 - len - The length of the byte stream 21 (both str1 and str2 are assumed to be of length len) 22 23 Output Parameters: 24 . e - `PETSC_TRUE` if equal else `PETSC_FALSE`. 25 26 Level: intermediate 27 28 Notes: 29 `PetscArraycmp()` is preferred 30 31 This routine is anologous to `memcmp()` with additional error checking 32 33 .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 34 `PetscArraymove()` 35 @*/ 36 PetscErrorCode PetscMemcmp(const void *str1, const void *str2, size_t len, PetscBool *e) { 37 if (!len) { 38 // if e is a bad ptr I guess we just die here then? 39 *e = PETSC_TRUE; 40 return 0; 41 } 42 43 PetscFunctionBegin; 44 PetscValidPointer(str1, 1); 45 PetscValidPointer(str2, 2); 46 PetscValidBoolPointer(e, 4); 47 *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE; 48 PetscFunctionReturn(0); 49 } 50 51 #if defined(PETSC_HAVE_HWLOC) 52 #include <petsc/private/petscimpl.h> 53 #include <hwloc.h> 54 55 /*@C 56 PetscProcessPlacementView - display the MPI rank placement by core 57 58 Input Parameter: 59 . viewer - ASCII viewer to display the results on 60 61 Level: intermediate 62 63 Note: 64 Requires that PETSc be installed with hwloc, for example using --download-hwloc 65 @*/ 66 PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) { 67 PetscBool isascii; 68 PetscMPIInt rank; 69 hwloc_bitmap_t set; 70 hwloc_topology_t topology; 71 72 PetscFunctionBegin; 73 PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 74 PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 75 PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported"); 76 77 PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); 78 hwloc_topology_init(&topology); 79 hwloc_topology_load(topology); 80 set = hwloc_bitmap_alloc(); 81 82 PetscCallExternal(hwloc_get_proc_cpubind, topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 83 PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 84 PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %d coreid %d\n", rank, getpid(), hwloc_bitmap_first(set))); 85 PetscCall(PetscViewerFlush(viewer)); 86 hwloc_bitmap_free(set); 87 hwloc_topology_destroy(topology); 88 PetscFunctionReturn(0); 89 } 90 #endif 91