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 <petscviewer.h>
9: #include <../src/sys/utils/ftn-kernels/fcopy.h>
11: /*@
12: PetscMemcmp - Compares two byte streams in memory.
14: Not Collective
16: Input Parameters:
17: + str1 - Pointer to the first byte stream
18: . str2 - Pointer to the second byte stream
19: - len - The length of the byte stream
20: (both str1 and str2 are assumed to be of length len)
22: Output Parameter:
23: . e - `PETSC_TRUE` if equal else `PETSC_FALSE`.
25: Level: intermediate
27: Notes:
28: `PetscArraycmp()` is preferred
30: This routine is analogous to `memcmp()` with additional error checking
32: .seealso: `PetscMemcpy()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`,
33: `PetscArraymove()`
34: @*/
35: PetscErrorCode PetscMemcmp(const void *str1, const void *str2, size_t len, PetscBool *e)
36: {
37: if (!len) {
38: // if e is a bad ptr I guess we just die here then?
39: *e = PETSC_TRUE;
40: return PETSC_SUCCESS;
41: }
43: PetscFunctionBegin;
44: PetscAssertPointer(str1, 1);
45: PetscAssertPointer(str2, 2);
46: PetscAssertPointer(e, 4);
47: *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE;
48: PetscFunctionReturn(PETSC_SUCCESS);
49: }
51: #if defined(PETSC_HAVE_HWLOC)
52: #include <hwloc.h>
53: #if defined(HWLOC_HAVE_WINDOWS_H)
54: // hwloc_pid_t is a HANDLE on Windows, and hwloc.h has already included windows.h
55: #define PetscHwlocSelf() GetCurrentProcess()
56: #define PetscHwlocPid() ((unsigned long)GetCurrentProcessId())
57: #else
58: #define PetscHwlocSelf() getpid()
59: #define PetscHwlocPid() ((unsigned long)getpid())
60: #endif
61: #endif
63: /*@
64: PetscProcessPlacementView - display the MPI rank placement by core
66: Input Parameter:
67: . viewer - `PETSCVIEWERASCII` to display the results on
69: Level: intermediate
71: Note:
72: Requires that PETSc be installed with hwloc, for example using `--download-hwloc`
74: .seealso: `PetscInitialize()`
75: @*/
76: PetscErrorCode PetscProcessPlacementView(PetscViewer viewer)
77: {
78: #if defined(PETSC_HAVE_HWLOC)
79: PetscBool isascii;
80: PetscMPIInt rank;
81: hwloc_bitmap_t set;
82: hwloc_topology_t topology;
84: PetscFunctionBegin;
86: PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
87: PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported");
89: PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
90: hwloc_topology_init(&topology);
91: hwloc_topology_load(topology);
92: set = hwloc_bitmap_alloc();
94: PetscCallExternal(hwloc_get_proc_cpubind, topology, PetscHwlocSelf(), set, HWLOC_CPUBIND_PROCESS);
95: PetscCall(PetscViewerASCIIPushSynchronized(viewer));
96: PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %lu coreid %d\n", rank, PetscHwlocPid(), hwloc_bitmap_first(set)));
97: PetscCall(PetscViewerFlush(viewer));
98: hwloc_bitmap_free(set);
99: hwloc_topology_destroy(topology);
100: #else
101: PetscFunctionBegin;
102: SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Requires PETSc be configured with --with-hwloc or --download-hwloc");
103: #endif
104: PetscFunctionReturn(PETSC_SUCCESS);
105: }