Actual source code: memc.c
1: /*
2: We define the memory operations here. The reason we just do not use
3: the standard memory routines in the PETSc code is that on some machines
4: they are broken.
6: */
7: #include <petsc/private/petscimpl.h>
8: #include <../src/sys/utils/ftn-kernels/fcopy.h>
10: /*@
11: PetscMemcmp - Compares two byte streams in memory.
13: Not Collective
15: Input Parameters:
16: + str1 - Pointer to the first byte stream
17: . str2 - Pointer to the second byte stream
18: - len - The length of the byte stream
19: (both str1 and str2 are assumed to be of length len)
21: Output Parameter:
22: . e - `PETSC_TRUE` if equal else `PETSC_FALSE`.
24: Level: intermediate
26: Notes:
27: `PetscArraycmp()` is preferred
29: This routine is analogous to `memcmp()` with additional error checking
31: .seealso: `PetscMemcpy()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`,
32: `PetscArraymove()`
33: @*/
34: PetscErrorCode PetscMemcmp(const void *str1, const void *str2, size_t len, PetscBool *e)
35: {
36: if (!len) {
37: // if e is a bad ptr I guess we just die here then?
38: *e = PETSC_TRUE;
39: return PETSC_SUCCESS;
40: }
42: PetscFunctionBegin;
43: PetscAssertPointer(str1, 1);
44: PetscAssertPointer(str2, 2);
45: PetscAssertPointer(e, 4);
46: *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE;
47: PetscFunctionReturn(PETSC_SUCCESS);
48: }
50: #if PetscDefined(HAVE_HWLOC)
51: #include <hwloc.h>
52: #if defined(HWLOC_HAVE_WINDOWS_H)
53: // hwloc_pid_t is a HANDLE on Windows, and hwloc.h has already included windows.h
54: #define PetscHwlocSelf() GetCurrentProcess()
55: #define PetscHwlocPid() ((unsigned long)GetCurrentProcessId())
56: #else
57: #define PetscHwlocSelf() getpid()
58: #define PetscHwlocPid() ((unsigned long)getpid())
59: #endif
60: #endif
62: /*@
63: PetscProcessPlacementView - display the MPI rank placement by core
65: Input Parameter:
66: . viewer - `PETSCVIEWERASCII` to display the results on
68: Level: intermediate
70: Note:
71: Requires that PETSc be installed with hwloc, for example using `--download-hwloc`
73: .seealso: `PetscInitialize()`
74: @*/
75: PetscErrorCode PetscProcessPlacementView(PetscViewer viewer)
76: {
77: #if PetscDefined(HAVE_HWLOC)
78: PetscBool isascii;
79: PetscMPIInt rank;
80: hwloc_bitmap_t set;
81: hwloc_topology_t topology;
83: PetscFunctionBegin;
85: PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
86: PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported");
88: PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
89: hwloc_topology_init(&topology);
90: hwloc_topology_load(topology);
91: set = hwloc_bitmap_alloc();
93: PetscCallExternal(hwloc_get_proc_cpubind, topology, PetscHwlocSelf(), set, HWLOC_CPUBIND_PROCESS);
94: PetscCall(PetscViewerASCIIPushSynchronized(viewer));
95: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %lu coreid %d\n", rank, PetscHwlocPid(), hwloc_bitmap_first(set)));
96: PetscCall(PetscViewerFlush(viewer));
97: hwloc_bitmap_free(set);
98: hwloc_topology_destroy(topology);
99: #else
100: PetscFunctionBegin;
101: SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Requires PETSc be configured with --with-hwloc or --download-hwloc");
102: #endif
103: PetscFunctionReturn(PETSC_SUCCESS);
104: }