memc.c (e366c154b69cf29c88be23f768f0f07dd2b3250c) memc.c (5e71baeff2f3138f93cd4f5927dfd596eb8325cc)
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>
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
11
14
12#undef __FUNCT__
13#define __FUNCT__ "PetscMemcmp"
14/*@
15 PetscMemcmp - Compares two byte streams in memory.
16
17 Not Collective
18
19 Input Parameters:
20+ str1 - Pointer to the first byte stream
21. str2 - Pointer to the second byte stream

--- 16 unchanged lines hidden (view full) ---

38 if (len > 0 && !str1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
39 if (len > 0 && !str2) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
40 r = memcmp((char*)str1,(char*)str2,len);
41 if (!r) *e = PETSC_TRUE;
42 else *e = PETSC_FALSE;
43 PetscFunctionReturn(0);
44}
45
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

--- 16 unchanged lines hidden (view full) ---

39 if (len > 0 && !str1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
40 if (len > 0 && !str2) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to compare at a null pointer");
41 r = memcmp((char*)str1,(char*)str2,len);
42 if (!r) *e = PETSC_TRUE;
43 else *e = PETSC_FALSE;
44 PetscFunctionReturn(0);
45}
46
46#undef __FUNCT__
47#define __FUNCT__ "PetscMemmove"
48/*@
49 PetscMemmove - Copies n bytes, beginning at location b, to the space
50 beginning at location a. Copying between regions that overlap will
51 take place correctly.
52
53 Not Collective
54
55 Input Parameters:

--- 35 unchanged lines hidden (view full) ---

91 }
92 }
93#else
94 memmove((char*)(a),(char*)(b),n);
95#endif
96 PetscFunctionReturn(0);
97}
98
47/*@
48 PetscMemmove - Copies n bytes, beginning at location b, to the space
49 beginning at location a. Copying between regions that overlap will
50 take place correctly.
51
52 Not Collective
53
54 Input Parameters:

--- 35 unchanged lines hidden (view full) ---

90 }
91 }
92#else
93 memmove((char*)(a),(char*)(b),n);
94#endif
95 PetscFunctionReturn(0);
96}
97
98#if defined(PETSC_HAVE_HWLOC)
99#include <petsc/private/petscimpl.h>
100#include <hwloc.h>
99
101
102#undef __FUNCT__
103#define __FUNCT__ "PetscProcessPlacementView"
104/*@
105 PetscProcessPlacementView - display the MPI process placement by core
100
106
107 Input Parameter:
108. viewer - ASCII viewer to display the results on
101
109
110 Notes: Requires that PETSc be installed with hwloc, for example using --download-hwloc
111@*/
112PetscErrorCode PetscProcessPlacementView(PetscViewer viewer)
113{
114 PetscErrorCode ierr;
115 PetscBool isascii;
116 PetscMPIInt rank;
117 hwloc_bitmap_t set;
118 hwloc_topology_t topology;
119 int err;
120
121 PetscFunctionBegin;
122 PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
123 ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
124 if (!isascii) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Only ASCII viewer is supported");
125
126 ierr = MPI_Comm_rank(MPI_COMM_WORLD,&rank);CHKERRQ(ierr);
127 hwloc_topology_init ( &topology);
128 hwloc_topology_load ( topology);
129 set = hwloc_bitmap_alloc();
130
131 err = hwloc_get_proc_cpubind(topology, getpid(), set, HWLOC_CPUBIND_PROCESS);
132 if (err) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error %d from hwloc_get_proc_cpubind()",err);
133 ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr);
134 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"MPI rank %d Process id: %d coreid %d\n",rank,getpid(),hwloc_bitmap_first(set));CHKERRQ(ierr);
135 ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
136 hwloc_bitmap_free(set);
137 hwloc_topology_destroy(topology);
138 PetscFunctionReturn(0);
139}
140#endif
141