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 23*2fe279fdSBarry Smith Output Parameter: 24811af0c4SBarry Smith . e - `PETSC_TRUE` if equal else `PETSC_FALSE`. 25e5c89e4eSSatish Balay 26e5c89e4eSSatish Balay Level: intermediate 27e5c89e4eSSatish Balay 28811af0c4SBarry Smith Notes: 29811af0c4SBarry Smith `PetscArraycmp()` is preferred 30811af0c4SBarry Smith 3135cb6cd3SPierre Jolivet This routine is analogous to `memcmp()` with additional error checking 32580bdb30SBarry Smith 33db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 34db781477SPatrick Sanan `PetscArraymove()` 35e5c89e4eSSatish Balay @*/ 36d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscMemcmp(const void *str1, const void *str2, size_t len, PetscBool *e) 37d71ae5a4SJacob Faibussowitsch { 385f80ce2aSJacob Faibussowitsch if (!len) { 395f80ce2aSJacob Faibussowitsch // if e is a bad ptr I guess we just die here then? 405f80ce2aSJacob Faibussowitsch *e = PETSC_TRUE; 413ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 425f80ce2aSJacob Faibussowitsch } 43c3e24edfSBarry Smith 44e5c89e4eSSatish Balay PetscFunctionBegin; 455f80ce2aSJacob Faibussowitsch PetscValidPointer(str1, 1); 465f80ce2aSJacob Faibussowitsch PetscValidPointer(str2, 2); 475f80ce2aSJacob Faibussowitsch PetscValidBoolPointer(e, 4); 485f80ce2aSJacob Faibussowitsch *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE; 493ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 50e5c89e4eSSatish Balay } 51e5c89e4eSSatish Balay 525e71baefSBarry Smith #if defined(PETSC_HAVE_HWLOC) 535e71baefSBarry Smith #include <petsc/private/petscimpl.h> 545e71baefSBarry Smith #include <hwloc.h> 55e5c89e4eSSatish Balay 5642218b76SBarry Smith /*@C 57811af0c4SBarry Smith PetscProcessPlacementView - display the MPI rank placement by core 58e5c89e4eSSatish Balay 595e71baefSBarry Smith Input Parameter: 60667f096bSBarry Smith . viewer - `PETSCVIEWERASCII` to display the results on 615e71baefSBarry Smith 6221fcc2ddSBarry Smith Level: intermediate 6321fcc2ddSBarry Smith 64811af0c4SBarry Smith Note: 6595452b02SPatrick Sanan Requires that PETSc be installed with hwloc, for example using --download-hwloc 665e71baefSBarry Smith @*/ 67d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) 68d71ae5a4SJacob Faibussowitsch { 695e71baefSBarry Smith PetscBool isascii; 705e71baefSBarry Smith PetscMPIInt rank; 715e71baefSBarry Smith hwloc_bitmap_t set; 725e71baefSBarry Smith hwloc_topology_t topology; 735e71baefSBarry Smith 745e71baefSBarry Smith PetscFunctionBegin; 755e71baefSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 769566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 775f80ce2aSJacob Faibussowitsch PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported"); 785e71baefSBarry Smith 799566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); 805e71baefSBarry Smith hwloc_topology_init(&topology); 815e71baefSBarry Smith hwloc_topology_load(topology); 825e71baefSBarry Smith set = hwloc_bitmap_alloc(); 835e71baefSBarry Smith 84792fecdfSBarry Smith PetscCallExternal(hwloc_get_proc_cpubind, topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 859566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 869566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %d coreid %d\n", rank, getpid(), hwloc_bitmap_first(set))); 879566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 885e71baefSBarry Smith hwloc_bitmap_free(set); 895e71baefSBarry Smith hwloc_topology_destroy(topology); 903ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 915e71baefSBarry Smith } 925e71baefSBarry Smith #endif 93