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: 24e5c89e4eSSatish Balay . e - PETSC_TRUE if equal else PETSC_FALSE. 25e5c89e4eSSatish Balay 26e5c89e4eSSatish Balay Level: intermediate 27e5c89e4eSSatish Balay 28e5c89e4eSSatish Balay Note: 29857a15f1SBarry Smith PetscArraycmp() is preferred 30e5c89e4eSSatish Balay This routine is anologous to memcmp() 31580bdb30SBarry Smith 32db781477SPatrick Sanan .seealso: `PetscMemcpy()`, `PetscMemcmp()`, `PetscArrayzero()`, `PetscMemzero()`, `PetscArraycmp()`, `PetscArraycpy()`, `PetscStrallocpy()`, 33db781477SPatrick Sanan `PetscArraymove()` 34e5c89e4eSSatish Balay @*/ 35*9371c9d4SSatish Balay PetscErrorCode PetscMemcmp(const void *str1, const void *str2, size_t len, PetscBool *e) { 365f80ce2aSJacob Faibussowitsch if (!len) { 375f80ce2aSJacob Faibussowitsch // if e is a bad ptr I guess we just die here then? 385f80ce2aSJacob Faibussowitsch *e = PETSC_TRUE; 395f80ce2aSJacob Faibussowitsch return 0; 405f80ce2aSJacob Faibussowitsch } 41c3e24edfSBarry Smith 42e5c89e4eSSatish Balay PetscFunctionBegin; 435f80ce2aSJacob Faibussowitsch PetscValidPointer(str1, 1); 445f80ce2aSJacob Faibussowitsch PetscValidPointer(str2, 2); 455f80ce2aSJacob Faibussowitsch PetscValidBoolPointer(e, 4); 465f80ce2aSJacob Faibussowitsch *e = memcmp((char *)str1, (char *)str2, len) ? PETSC_FALSE : PETSC_TRUE; 47e5c89e4eSSatish Balay PetscFunctionReturn(0); 48e5c89e4eSSatish Balay } 49e5c89e4eSSatish Balay 505e71baefSBarry Smith #if defined(PETSC_HAVE_HWLOC) 515e71baefSBarry Smith #include <petsc/private/petscimpl.h> 525e71baefSBarry Smith #include <hwloc.h> 53e5c89e4eSSatish Balay 5442218b76SBarry Smith /*@C 555e71baefSBarry Smith PetscProcessPlacementView - display the MPI process placement by core 56e5c89e4eSSatish Balay 575e71baefSBarry Smith Input Parameter: 585e71baefSBarry Smith . viewer - ASCII viewer to display the results on 595e71baefSBarry Smith 6021fcc2ddSBarry Smith Level: intermediate 6121fcc2ddSBarry Smith 6295452b02SPatrick Sanan Notes: 6395452b02SPatrick Sanan Requires that PETSc be installed with hwloc, for example using --download-hwloc 645e71baefSBarry Smith @*/ 65*9371c9d4SSatish Balay PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) { 665e71baefSBarry Smith PetscBool isascii; 675e71baefSBarry Smith PetscMPIInt rank; 685e71baefSBarry Smith hwloc_bitmap_t set; 695e71baefSBarry Smith hwloc_topology_t topology; 705e71baefSBarry Smith 715e71baefSBarry Smith PetscFunctionBegin; 725e71baefSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 739566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 745f80ce2aSJacob Faibussowitsch PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Only ASCII viewer is supported"); 755e71baefSBarry Smith 769566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); 775e71baefSBarry Smith hwloc_topology_init(&topology); 785e71baefSBarry Smith hwloc_topology_load(topology); 795e71baefSBarry Smith set = hwloc_bitmap_alloc(); 805e71baefSBarry Smith 81792fecdfSBarry Smith PetscCallExternal(hwloc_get_proc_cpubind, topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 829566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushSynchronized(viewer)); 839566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIISynchronizedPrintf(viewer, "MPI rank %d Process id: %d coreid %d\n", rank, getpid(), hwloc_bitmap_first(set))); 849566063dSJacob Faibussowitsch PetscCall(PetscViewerFlush(viewer)); 855e71baefSBarry Smith hwloc_bitmap_free(set); 865e71baefSBarry Smith hwloc_topology_destroy(topology); 875e71baefSBarry Smith PetscFunctionReturn(0); 885e71baefSBarry Smith } 895e71baefSBarry Smith #endif 90