Actual source code: memc.c
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.
7: */
8: #include <petsc/private/petscimpl.h>
9: #include <petscbt.h>
10: #include <../src/sys/utils/ftn-kernels/fcopy.h>
12: /*@
13: PetscMemcmp - Compares two byte streams in memory.
15: Not Collective
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)
23: Output Parameter:
24: . e - `PETSC_TRUE` if equal else `PETSC_FALSE`.
26: Level: intermediate
28: Notes:
29: `PetscArraycmp()` is preferred
31: This routine is analogous to `memcmp()` with additional error checking
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: {
38: if (!len) {
39: // if e is a bad ptr I guess we just die here then?
40: *e = PETSC_TRUE;
41: return PETSC_SUCCESS;
42: }
44: PetscFunctionBegin;
48: *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE;
49: PetscFunctionReturn(PETSC_SUCCESS);
50: }
52: #if defined(PETSC_HAVE_HWLOC)
53: #include <petsc/private/petscimpl.h>
54: #include <hwloc.h>
56: /*@C
57: PetscProcessPlacementView - display the MPI rank placement by core
59: Input Parameter:
60: . viewer - `PETSCVIEWERASCII` to display the results on
62: Level: intermediate
64: Note:
65: Requires that PETSc be installed with hwloc, for example using --download-hwloc
66: @*/
67: PetscErrorCode PetscProcessPlacementView(PetscViewer viewer)
68: {
69: PetscBool isascii;
70: PetscMPIInt rank;
71: hwloc_bitmap_t set;
72: hwloc_topology_t topology;
74: PetscFunctionBegin;
76: PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
77: PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported");
79: PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
80: hwloc_topology_init(&topology);
81: hwloc_topology_load(topology);
82: set = hwloc_bitmap_alloc();
84: PetscCallExternal(hwloc_get_proc_cpubind, topology, getpid(), set, HWLOC_CPUBIND_PROCESS);
85: PetscCall(PetscViewerASCIIPushSynchronized(viewer));
86: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %d coreid %d\n", rank, getpid(), hwloc_bitmap_first(set)));
87: PetscCall(PetscViewerFlush(viewer));
88: hwloc_bitmap_free(set);
89: hwloc_topology_destroy(topology);
90: PetscFunctionReturn(PETSC_SUCCESS);
91: }
92: #endif