1e5c89e4eSSatish Balay 2e5c89e4eSSatish Balay /* 3e5c89e4eSSatish Balay We define the memory operations here. The reason we just do not use 4e5c89e4eSSatish Balay the standard memory routines in the PETSc code is that on some machines 5e5c89e4eSSatish Balay they are broken. 6e5c89e4eSSatish Balay 7e5c89e4eSSatish Balay */ 85f80ce2aSJacob Faibussowitsch #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 9c6db04a5SJed Brown #include <petscbt.h> 10c6db04a5SJed Brown #include <../src/sys/utils/ftn-kernels/fcopy.h> 11e5c89e4eSSatish Balay 124610e317SSatish Balay /*@ 13e5c89e4eSSatish Balay PetscMemcmp - Compares two byte streams in memory. 14e5c89e4eSSatish Balay 15e5c89e4eSSatish Balay Not Collective 16e5c89e4eSSatish Balay 17e5c89e4eSSatish Balay Input Parameters: 18e5c89e4eSSatish Balay + str1 - Pointer to the first byte stream 19e5c89e4eSSatish Balay . str2 - Pointer to the second byte stream 20e5c89e4eSSatish Balay - len - The length of the byte stream 21e5c89e4eSSatish Balay (both str1 and str2 are assumed to be of length len) 22e5c89e4eSSatish Balay 23e5c89e4eSSatish Balay Output Parameters: 24*811af0c4SBarry Smith . e - `PETSC_TRUE` if equal else `PETSC_FALSE`. 25e5c89e4eSSatish Balay 26e5c89e4eSSatish Balay Level: intermediate 27e5c89e4eSSatish Balay 28*811af0c4SBarry Smith Notes: 29*811af0c4SBarry Smith `PetscArraycmp()` is preferred 30*811af0c4SBarry Smith 31*811af0c4SBarry Smith This routine is anologous to `memcmp()` with additional error checking 32580bdb30SBarry Smith 33db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 34db781477SPatrick Sanan `PetscArraymove()` 35e5c89e4eSSatish Balay @*/ 369371c9d4SSatish Balay PetscErrorCode PetscMemcmp(const void *str1, const void *str2, size_t len, PetscBool *e) { 375f80ce2aSJacob Faibussowitsch if (!len) { 385f80ce2aSJacob Faibussowitsch // if e is a bad ptr I guess we just die here then? 395f80ce2aSJacob Faibussowitsch *e = PETSC_TRUE; 405f80ce2aSJacob Faibussowitsch return 0; 415f80ce2aSJacob Faibussowitsch } 42c3e24edfSBarry Smith 43e5c89e4eSSatish Balay PetscFunctionBegin; 445f80ce2aSJacob Faibussowitsch PetscValidPointer(str1, 1); 455f80ce2aSJacob Faibussowitsch PetscValidPointer(str2, 2); 465f80ce2aSJacob Faibussowitsch PetscValidBoolPointer(e, 4); 475f80ce2aSJacob Faibussowitsch *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE; 48e5c89e4eSSatish Balay PetscFunctionReturn(0); 49e5c89e4eSSatish Balay } 50e5c89e4eSSatish Balay 515e71baefSBarry Smith #if defined(PETSC_HAVE_HWLOC) 525e71baefSBarry Smith #include <petsc/private/petscimpl.h> 535e71baefSBarry Smith #include <hwloc.h> 54e5c89e4eSSatish Balay 5542218b76SBarry Smith /*@C 56*811af0c4SBarry Smith PetscProcessPlacementView - display the MPI rank placement by core 57e5c89e4eSSatish Balay 585e71baefSBarry Smith Input Parameter: 595e71baefSBarry Smith . viewer - ASCII viewer to display the results on 605e71baefSBarry Smith 6121fcc2ddSBarry Smith Level: intermediate 6221fcc2ddSBarry Smith 63*811af0c4SBarry Smith Note: 6495452b02SPatrick Sanan Requires that PETSc be installed with hwloc, for example using --download-hwloc 655e71baefSBarry Smith @*/ 669371c9d4SSatish Balay PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) { 675e71baefSBarry Smith PetscBool isascii; 685e71baefSBarry Smith PetscMPIInt rank; 695e71baefSBarry Smith hwloc_bitmap_t set; 705e71baefSBarry Smith hwloc_topology_t topology; 715e71baefSBarry Smith 725e71baefSBarry Smith PetscFunctionBegin; 735e71baefSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 749566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 755f80ce2aSJacob Faibussowitsch PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported"); 765e71baefSBarry Smith 779566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); 785e71baefSBarry Smith hwloc_topology_init(&topology); 795e71baefSBarry Smith hwloc_topology_load(topology); 805e71baefSBarry Smith set = hwloc_bitmap_alloc(); 815e71baefSBarry Smith 82792fecdfSBarry Smith PetscCallExternal(hwloc_get_proc_cpubind, topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 839566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 849566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %d coreid %d\n", rank, getpid(), hwloc_bitmap_first(set))); 859566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 865e71baefSBarry Smith hwloc_bitmap_free(set); 875e71baefSBarry Smith hwloc_topology_destroy(topology); 885e71baefSBarry Smith PetscFunctionReturn(0); 895e71baefSBarry Smith } 905e71baefSBarry Smith #endif 91