Actual source code: memc.c

petsc-3.13.6 2020-09-29
Report Typos and Errors

  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.

  7: */
  8:  #include <petscsys.h>
  9:  #include <petscbt.h>
 10:  #include <../src/sys/utils/ftn-kernels/fcopy.h>

 12: /*@
 13:    PetscMemcmp - Compares two byte streams in memory.

 15:    Not Collective

 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)

 23:    Output Parameters:
 24: .   e - PETSC_TRUE if equal else PETSC_FALSE.

 26:    Level: intermediate

 28:    Note:
 29:    PetscArraycmp() is preferred
 30:    This routine is anologous to memcmp()

 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;

 40:   if (len > 0 && !str1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
 41:   if (len > 0 && !str2) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
 42:   r = memcmp((char*)str1,(char*)str2,len);
 43:   if (!r) *e = PETSC_TRUE;
 44:   else    *e = PETSC_FALSE;
 45:   return(0);
 46: }

 48: #if defined(PETSC_HAVE_HWLOC)
 49:  #include <petsc/private/petscimpl.h>
 50: #include <hwloc.h>

 52: /*@C
 53:      PetscProcessPlacementView - display the MPI process placement by core

 55:   Input Parameter:
 56: .   viewer - ASCII viewer to display the results on

 58:   Level: intermediate

 60:   Notes:
 61:     Requires that PETSc be installed with hwloc, for example using --download-hwloc
 62: @*/
 63: PetscErrorCode PetscProcessPlacementView(PetscViewer viewer)
 64: {
 65:   PetscErrorCode   ierr;
 66:   PetscBool        isascii;
 67:   PetscMPIInt      rank;
 68:   hwloc_bitmap_t   set;
 69:   hwloc_topology_t topology;
 70:   int              err;

 74:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
 75:   if (!isascii) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Only ASCII viewer is supported");

 77:   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
 78:   hwloc_topology_init ( &topology);
 79:   hwloc_topology_load ( topology);
 80:   set = hwloc_bitmap_alloc();

 82:   err = hwloc_get_proc_cpubind(topology, getpid(), set, HWLOC_CPUBIND_PROCESS);
 83:   if (err) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error %d from hwloc_get_proc_cpubind()",err);
 84:   PetscViewerASCIIPushSynchronized(viewer);
 85:   PetscViewerASCIISynchronizedPrintf(viewer,"MPI rank %d Process id: %d coreid %d\n",rank,getpid(),hwloc_bitmap_first(set));
 86:   PetscViewerFlush(viewer);
 87:   hwloc_bitmap_free(set);
 88:   hwloc_topology_destroy(topology);
 89:   return(0);
 90: }
 91: #endif