1 2 /* 3 We define the memory operations here. The reason we just do not use 4 the standard memory routines in the PETSc code is that on some machines 5 they are broken. 6 7 */ 8 #include <petscsys.h> /*I "petscsys.h" I*/ 9 #include <petscbt.h> 10 #include <../src/sys/utils/ftn-kernels/fcopy.h> 11 12 /*@ 13 PetscMemcmp - Compares two byte streams in memory. 14 15 Not Collective 16 17 Input Parameters: 18 + str1 - Pointer to the first byte stream 19 . str2 - Pointer to the second byte stream 20 - len - The length of the byte stream 21 (both str1 and str2 are assumed to be of length len) 22 23 Output Parameters: 24 . e - PETSC_TRUE if equal else PETSC_FALSE. 25 26 Level: intermediate 27 28 Note: 29 PetscArraycmp() is preferred 30 This routine is anologous to memcmp() 31 32 .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscMemzero(), PetscArraycmp(), PetscArraycpy(), PetscStrallocpy(), 33 PetscArraymove() 34 @*/ 35 PetscErrorCode PetscMemcmp(const void *str1,const void *str2,size_t len,PetscBool *e) 36 { 37 int r; 38 39 if (!len) {*e = PETSC_TRUE; return 0;} 40 41 PetscFunctionBegin; 42 PetscCheckFalse(!str1,PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer"); 43 PetscCheckFalse(!str2,PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer"); 44 r = memcmp((char*)str1,(char*)str2,len); 45 if (!r) *e = PETSC_TRUE; 46 else *e = PETSC_FALSE; 47 PetscFunctionReturn(0); 48 } 49 50 #if defined(PETSC_HAVE_HWLOC) 51 #include <petsc/private/petscimpl.h> 52 #include <hwloc.h> 53 54 /*@C 55 PetscProcessPlacementView - display the MPI process placement by core 56 57 Input Parameter: 58 . viewer - ASCII viewer to display the results on 59 60 Level: intermediate 61 62 Notes: 63 Requires that PETSc be installed with hwloc, for example using --download-hwloc 64 @*/ 65 PetscErrorCode PetscProcessPlacementView(PetscViewer viewer) 66 { 67 PetscErrorCode ierr; 68 PetscBool isascii; 69 PetscMPIInt rank; 70 hwloc_bitmap_t set; 71 hwloc_topology_t topology; 72 int err; 73 74 PetscFunctionBegin; 75 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 76 ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr); 77 PetscCheckFalse(!isascii,PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Only ASCII viewer is supported"); 78 79 ierr = MPI_Comm_rank(MPI_COMM_WORLD,&rank);CHKERRMPI(ierr); 80 hwloc_topology_init ( &topology); 81 hwloc_topology_load ( topology); 82 set = hwloc_bitmap_alloc(); 83 84 err = hwloc_get_proc_cpubind(topology, getpid(), set, HWLOC_CPUBIND_PROCESS); 85 PetscCheckFalse(err,PETSC_COMM_SELF,PETSC_ERR_LIB,"Error %d from hwloc_get_proc_cpubind()",err); 86 ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); 87 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"MPI rank %d Process id: %d coreid %d\n",rank,getpid(),hwloc_bitmap_first(set));CHKERRQ(ierr); 88 ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 89 hwloc_bitmap_free(set); 90 hwloc_topology_destroy(topology); 91 PetscFunctionReturn(0); 92 } 93 #endif 94 95