xref: /petsc/src/sys/utils/memc.c (revision 857a15f11b37d00b54a65cc362184bc61b45e4ba)
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>
118a2c3ff8SSatish Balay #if defined(PETSC_HAVE_STRING_H)
128a2c3ff8SSatish Balay #include <string.h>
138a2c3ff8SSatish Balay #endif
14e5c89e4eSSatish Balay 
154610e317SSatish Balay /*@
16e5c89e4eSSatish Balay    PetscMemcmp - Compares two byte streams in memory.
17e5c89e4eSSatish Balay 
18e5c89e4eSSatish Balay    Not Collective
19e5c89e4eSSatish Balay 
20e5c89e4eSSatish Balay    Input Parameters:
21e5c89e4eSSatish Balay +  str1 - Pointer to the first byte stream
22e5c89e4eSSatish Balay .  str2 - Pointer to the second byte stream
23e5c89e4eSSatish Balay -  len  - The length of the byte stream
24e5c89e4eSSatish Balay          (both str1 and str2 are assumed to be of length len)
25e5c89e4eSSatish Balay 
26e5c89e4eSSatish Balay    Output Parameters:
27e5c89e4eSSatish Balay .   e - PETSC_TRUE if equal else PETSC_FALSE.
28e5c89e4eSSatish Balay 
29e5c89e4eSSatish Balay    Level: intermediate
30e5c89e4eSSatish Balay 
31e5c89e4eSSatish Balay    Note:
32*857a15f1SBarry Smith    PetscArraycmp() is preferred
33e5c89e4eSSatish Balay    This routine is anologous to memcmp()
34580bdb30SBarry Smith 
35580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscMemzero(), PetscArraycmp(), PetscArraycpy(), PetscStrallocpy(),
36580bdb30SBarry Smith           PetscArraymove()
37e5c89e4eSSatish Balay @*/
387087cfbeSBarry Smith PetscErrorCode  PetscMemcmp(const void *str1,const void *str2,size_t len,PetscBool  *e)
39e5c89e4eSSatish Balay {
40e5c89e4eSSatish Balay   int r;
41e5c89e4eSSatish Balay 
42e5c89e4eSSatish Balay   PetscFunctionBegin;
43e32f2f54SBarry Smith   if (len > 0 && !str1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
44e32f2f54SBarry Smith   if (len > 0 && !str2) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
45e5c89e4eSSatish Balay   r = memcmp((char*)str1,(char*)str2,len);
46e5c89e4eSSatish Balay   if (!r) *e = PETSC_TRUE;
47e5c89e4eSSatish Balay   else    *e = PETSC_FALSE;
48e5c89e4eSSatish Balay   PetscFunctionReturn(0);
49e5c89e4eSSatish Balay }
50e5c89e4eSSatish Balay 
515e71baefSBarry Smith #if defined(PETSC_HAVE_HWLOC)
525e71baefSBarry Smith #include <petsc/private/petscimpl.h>
535e71baefSBarry Smith #include <hwloc.h>
54e5c89e4eSSatish Balay 
5542218b76SBarry Smith /*@C
565e71baefSBarry Smith      PetscProcessPlacementView - display the MPI process placement by core
57e5c89e4eSSatish Balay 
585e71baefSBarry Smith   Input Parameter:
595e71baefSBarry Smith .   viewer - ASCII viewer to display the results on
605e71baefSBarry Smith 
6121fcc2ddSBarry Smith   Level: intermediate
6221fcc2ddSBarry Smith 
6395452b02SPatrick Sanan   Notes:
6495452b02SPatrick Sanan     Requires that PETSc be installed with hwloc, for example using --download-hwloc
655e71baefSBarry Smith @*/
665e71baefSBarry Smith PetscErrorCode PetscProcessPlacementView(PetscViewer viewer)
675e71baefSBarry Smith {
685e71baefSBarry Smith   PetscErrorCode   ierr;
695e71baefSBarry Smith   PetscBool        isascii;
705e71baefSBarry Smith   PetscMPIInt      rank;
715e71baefSBarry Smith   hwloc_bitmap_t   set;
725e71baefSBarry Smith   hwloc_topology_t topology;
735e71baefSBarry Smith   int              err;
745e71baefSBarry Smith 
755e71baefSBarry Smith   PetscFunctionBegin;
765e71baefSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
77928bb9adSStefano Zampini   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr);
785e71baefSBarry Smith   if (!isascii) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Only ASCII viewer is supported");
795e71baefSBarry Smith 
805e71baefSBarry Smith   ierr = MPI_Comm_rank(MPI_COMM_WORLD,&rank);CHKERRQ(ierr);
815e71baefSBarry Smith   hwloc_topology_init ( &topology);
825e71baefSBarry Smith   hwloc_topology_load ( topology);
835e71baefSBarry Smith   set = hwloc_bitmap_alloc();
845e71baefSBarry Smith 
855e71baefSBarry Smith   err = hwloc_get_proc_cpubind(topology, getpid(), set, HWLOC_CPUBIND_PROCESS);
865e71baefSBarry Smith   if (err) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error %d from hwloc_get_proc_cpubind()",err);
875e71baefSBarry Smith   ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr);
885e71baefSBarry Smith   ierr = PetscViewerASCIISynchronizedPrintf(viewer,"MPI rank %d Process id: %d coreid %d\n",rank,getpid(),hwloc_bitmap_first(set));CHKERRQ(ierr);
895e71baefSBarry Smith   ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
905e71baefSBarry Smith   hwloc_bitmap_free(set);
915e71baefSBarry Smith   hwloc_topology_destroy(topology);
925e71baefSBarry Smith   PetscFunctionReturn(0);
935e71baefSBarry Smith }
945e71baefSBarry Smith #endif
95e5c89e4eSSatish Balay 
96