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