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 */ 8c6db04a5SJed Brown #include <petscsys.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 32580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscMemzero(), PetscArraycmp(), PetscArraycpy(), PetscStrallocpy(), 33580bdb30SBarry Smith PetscArraymove() 34e5c89e4eSSatish Balay @*/ 357087cfbeSBarry Smith PetscErrorCode PetscMemcmp(const void *str1,const void *str2,size_t len,PetscBool *e) 36e5c89e4eSSatish Balay { 37e5c89e4eSSatish Balay int r; 38e5c89e4eSSatish Balay 39*c3e24edfSBarry Smith if (!len) {*e = PETSC_TRUE; return 0;} 40*c3e24edfSBarry Smith 41e5c89e4eSSatish Balay PetscFunctionBegin; 42*c3e24edfSBarry Smith if (!str1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer"); 43*c3e24edfSBarry Smith if (!str2) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer"); 44e5c89e4eSSatish Balay r = memcmp((char*)str1,(char*)str2,len); 45e5c89e4eSSatish Balay if (!r) *e = PETSC_TRUE; 46e5c89e4eSSatish Balay else *e = PETSC_FALSE; 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 @*/ 655e71baefSBarry Smith PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) 665e71baefSBarry Smith { 675e71baefSBarry Smith PetscErrorCode ierr; 685e71baefSBarry Smith PetscBool isascii; 695e71baefSBarry Smith PetscMPIInt rank; 705e71baefSBarry Smith hwloc_bitmap_t set; 715e71baefSBarry Smith hwloc_topology_t topology; 725e71baefSBarry Smith int err; 735e71baefSBarry Smith 745e71baefSBarry Smith PetscFunctionBegin; 755e71baefSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 76928bb9adSStefano Zampini ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr); 775e71baefSBarry Smith if (!isascii) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Only ASCII viewer is supported"); 785e71baefSBarry Smith 79ffc4695bSBarry Smith ierr = MPI_Comm_rank(MPI_COMM_WORLD,&rank);CHKERRMPI(ierr); 805e71baefSBarry Smith hwloc_topology_init ( &topology); 815e71baefSBarry Smith hwloc_topology_load ( topology); 825e71baefSBarry Smith set = hwloc_bitmap_alloc(); 835e71baefSBarry Smith 845e71baefSBarry Smith err = hwloc_get_proc_cpubind(topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 855e71baefSBarry Smith if (err) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error %d from hwloc_get_proc_cpubind()",err); 865e71baefSBarry Smith ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); 875e71baefSBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer,"MPI rank %d Process id: %d coreid %d\n",rank,getpid(),hwloc_bitmap_first(set));CHKERRQ(ierr); 885e71baefSBarry Smith ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 895e71baefSBarry Smith hwloc_bitmap_free(set); 905e71baefSBarry Smith hwloc_topology_destroy(topology); 915e71baefSBarry Smith PetscFunctionReturn(0); 925e71baefSBarry Smith } 935e71baefSBarry Smith #endif 94e5c89e4eSSatish Balay 95