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