Actual source code: dlregisvec.c

petsc-master 2019-08-18
Report Typos and Errors

  2:  #include <petsc/private/vecimpl.h>
  3:  #include <petsc/private/isimpl.h>
  4:  #include <petscpf.h>
  5:  #include <petscsf.h>
  6:  #include <petscao.h>

  8: static PetscBool         ISPackageInitialized = PETSC_FALSE;
  9: extern PetscFunctionList ISLocalToGlobalMappingList;

 11: /*@C
 12:   ISFinalizePackage - This function destroys everything in the IS package. It is
 13:   called from PetscFinalize().

 15:   Level: developer

 17: .seealso: PetscFinalize()
 18: @*/
 19: PetscErrorCode  ISFinalizePackage(void)
 20: {

 24:   PetscFunctionListDestroy(&ISList);
 25:   PetscFunctionListDestroy(&ISLocalToGlobalMappingList);
 26:   PetscFunctionListDestroy(&PetscSectionSymList);
 27:   ISPackageInitialized                    = PETSC_FALSE;
 28:   ISRegisterAllCalled                     = PETSC_FALSE;
 29:   ISLocalToGlobalMappingRegisterAllCalled = PETSC_FALSE;
 30:   return(0);
 31: }

 33: /*@C
 34:       ISInitializePackage - This function initializes everything in the IS package. It is called
 35:   from PetscDLLibraryRegister_petscvec() when using dynamic libraries, and on the first call to ISCreateXXXX()
 36:   when using shared or static libraries.

 38:   Level: developer

 40: .seealso: PetscInitialize()
 41: @*/
 42: PetscErrorCode  ISInitializePackage(void)
 43: {
 44:   char           logList[256];
 45:   PetscBool      opt,pkg;

 49:   if (ISPackageInitialized) return(0);
 50:   ISPackageInitialized = PETSC_TRUE;
 51:   /* Register Classes */
 52:   PetscClassIdRegister("Index Set",&IS_CLASSID);
 53:   PetscClassIdRegister("IS L to G Mapping",&IS_LTOGM_CLASSID);
 54:   PetscClassIdRegister("Section",&PETSC_SECTION_CLASSID);
 55:   PetscClassIdRegister("Section Symmetry",&PETSC_SECTION_SYM_CLASSID);
 56:   /* Register Constructors */
 57:   ISRegisterAll();
 58:   ISLocalToGlobalMappingRegisterAll();
 59:   /* Process info exclusions */
 60:   PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);
 61:   if (opt) {
 62:     PetscStrInList("is",logList,',',&pkg);
 63:     if (pkg) {PetscInfoDeactivateClass(IS_CLASSID);}
 64:     if (pkg) {PetscInfoDeactivateClass(IS_LTOGM_CLASSID);}
 65:     PetscStrInList("section",logList,',',&pkg);
 66:     if (pkg) {PetscInfoDeactivateClass(PETSC_SECTION_CLASSID);}
 67:     if (pkg) {PetscInfoDeactivateClass(PETSC_SECTION_SYM_CLASSID);}
 68:   }
 69:   /* Process summary exclusions */
 70:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
 71:   if (opt) {
 72:     PetscStrInList("is",logList,',',&pkg);
 73:     if (pkg) {PetscLogEventExcludeClass(IS_CLASSID);}
 74:     if (pkg) {PetscLogEventExcludeClass(IS_LTOGM_CLASSID);}
 75:     PetscStrInList("section",logList,',',&pkg);
 76:     if (pkg) {PetscLogEventExcludeClass(PETSC_SECTION_CLASSID);}
 77:     if (pkg) {PetscLogEventExcludeClass(PETSC_SECTION_SYM_CLASSID);}
 78:   }
 79:   /* Register package finalizer */
 80:   PetscRegisterFinalize(ISFinalizePackage);
 81:   return(0);
 82: }

 84: extern MPI_Op PetscSplitReduction_Op;

 86: /*
 87:        These two functions are the MPI reduction operation used for max and min with index
 88:    A call to MPI_Op_create() converts the function Vec[Max,Min]_Local() to the MPI operator Vec[Max,Min]_Local_Op.

 90: */
 91: MPI_Op MPIU_MAXINDEX_OP = 0;
 92: MPI_Op MPIU_MININDEX_OP = 0;

 94: static void MPIAPI MPIU_MaxIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
 95: {
 96:   PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;

 99:   if (*datatype != MPIU_REAL) {
100:     (*PetscErrorPrintf)("Can only handle MPIU_REAL data types");
101:     MPI_Abort(MPI_COMM_SELF,1);
102:   }
103:   if (xin[0] > xout[0]) {
104:     xout[0] = xin[0];
105:     xout[1] = xin[1];
106:   } else if (xin[0] == xout[0]) {
107:     xout[1] = PetscMin(xin[1],xout[1]);
108:   }
109:   PetscFunctionReturnVoid(); /* cannot return a value */
110: }

112: static void MPIAPI MPIU_MinIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
113: {
114:   PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;

117:   if (*datatype != MPIU_REAL) {
118:     (*PetscErrorPrintf)("Can only handle MPIU_REAL data types");
119:     MPI_Abort(MPI_COMM_SELF,1);
120:   }
121:   if (xin[0] < xout[0]) {
122:     xout[0] = xin[0];
123:     xout[1] = xin[1];
124:   } else if (xin[0] == xout[0]) {
125:     xout[1] = PetscMin(xin[1],xout[1]);
126:   }
127:   PetscFunctionReturnVoid();
128: }

130: PETSC_EXTERN void MPIAPI PetscSplitReduction_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);

132: const char *const NormTypes[] = {"1","2","FROBENIUS","INFINITY","1_AND_2","NormType","NORM_",0};
133: PetscInt          NormIds[7];  /* map from NormType to IDs used to cache Normvalues */

135: static PetscBool  VecPackageInitialized = PETSC_FALSE;

137: /*@C
138:   VecInitializePackage - This function initializes everything in the Vec package. It is called
139:   from PetscDLLibraryRegister_petscvec() when using dynamic libraries, and on the first call to VecCreate()
140:   when using shared or static libraries.

142:   Level: developer

144: .seealso: PetscInitialize()
145: @*/
146: PetscErrorCode  VecInitializePackage(void)
147: {
148:   char           logList[256];
149:   PetscBool      opt,pkg;
151:   PetscInt       i;

154:   if (VecPackageInitialized) return(0);
155:   VecPackageInitialized = PETSC_TRUE;
156:   /* Register Classes */
157:   PetscClassIdRegister("Vector",&VEC_CLASSID);
158:   /* Register Constructors */
159:   VecRegisterAll();
160:   /* Register Events */
161:   PetscLogEventRegister("VecView",          VEC_CLASSID,&VEC_View);
162:   PetscLogEventRegister("VecMax",           VEC_CLASSID,&VEC_Max);
163:   PetscLogEventRegister("VecMin",           VEC_CLASSID,&VEC_Min);
164:   PetscLogEventRegister("VecDot",           VEC_CLASSID,&VEC_Dot);
165:   PetscLogEventRegister("VecDotNorm2",      VEC_CLASSID,&VEC_DotNorm2);
166:   PetscLogEventRegister("VecMDot",          VEC_CLASSID,&VEC_MDot);
167:   PetscLogEventRegister("VecTDot",          VEC_CLASSID,&VEC_TDot);
168:   PetscLogEventRegister("VecMTDot",         VEC_CLASSID,&VEC_MTDot);
169:   PetscLogEventRegister("VecNorm",          VEC_CLASSID,&VEC_Norm);
170:   PetscLogEventRegister("VecScale",         VEC_CLASSID,&VEC_Scale);
171:   PetscLogEventRegister("VecCopy",          VEC_CLASSID,&VEC_Copy);
172:   PetscLogEventRegister("VecSet",           VEC_CLASSID,&VEC_Set);
173:   PetscLogEventRegister("VecAXPY",          VEC_CLASSID,&VEC_AXPY);
174:   PetscLogEventRegister("VecAYPX",          VEC_CLASSID,&VEC_AYPX);
175:   PetscLogEventRegister("VecAXPBYCZ",       VEC_CLASSID,&VEC_AXPBYPCZ);
176:   PetscLogEventRegister("VecWAXPY",         VEC_CLASSID,&VEC_WAXPY);
177:   PetscLogEventRegister("VecMAXPY",         VEC_CLASSID,&VEC_MAXPY);
178:   PetscLogEventRegister("VecSwap",          VEC_CLASSID,&VEC_Swap);
179:   PetscLogEventRegister("VecOps",           VEC_CLASSID,&VEC_Ops);
180:   PetscLogEventRegister("VecAssemblyBegin", VEC_CLASSID,&VEC_AssemblyBegin);
181:   PetscLogEventRegister("VecAssemblyEnd",   VEC_CLASSID,&VEC_AssemblyEnd);
182:   PetscLogEventRegister("VecPointwiseMult", VEC_CLASSID,&VEC_PointwiseMult);
183:   PetscLogEventRegister("VecSetValues",     VEC_CLASSID,&VEC_SetValues);
184:   PetscLogEventRegister("VecLoad",          VEC_CLASSID,&VEC_Load);
185:   PetscLogEventRegister("VecScatterBegin",  VEC_CLASSID,&VEC_ScatterBegin);
186:   PetscLogEventRegister("VecScatterEnd  ",  VEC_CLASSID,&VEC_ScatterEnd);
187:   PetscLogEventRegister("VecSetRandom",     VEC_CLASSID,&VEC_SetRandom);
188:   PetscLogEventRegister("VecReduceArith",   VEC_CLASSID,&VEC_ReduceArithmetic);
189:   PetscLogEventRegister("VecReduceComm",    VEC_CLASSID,&VEC_ReduceCommunication);
190:   PetscLogEventRegister("VecReduceBegin",   VEC_CLASSID,&VEC_ReduceBegin);
191:   PetscLogEventRegister("VecReduceEnd",     VEC_CLASSID,&VEC_ReduceEnd);
192:   PetscLogEventRegister("VecNormalize",     VEC_CLASSID,&VEC_Normalize);
193: #if defined(PETSC_HAVE_VIENNACL)
194:   PetscLogEventRegister("VecVCLCopyTo",     VEC_CLASSID,&VEC_ViennaCLCopyToGPU);
195:   PetscLogEventRegister("VecVCLCopyFrom",   VEC_CLASSID,&VEC_ViennaCLCopyFromGPU);
196: #endif
197: #if defined(PETSC_HAVE_CUDA)
198:   PetscLogEventRegister("VecCUDACopyTo",    VEC_CLASSID,&VEC_CUDACopyToGPU);
199:   PetscLogEventRegister("VecCUDACopyFrom",  VEC_CLASSID,&VEC_CUDACopyFromGPU);
200:   PetscLogEventRegister("VecCopyToSome",    VEC_CLASSID,&VEC_CUDACopyToGPUSome);
201:   PetscLogEventRegister("VecCopyFromSome",  VEC_CLASSID,&VEC_CUDACopyFromGPUSome);
202: #endif

204:   /* Mark non-collective events */
205:   PetscLogEventSetCollective(VEC_SetValues,           PETSC_FALSE);
206: #if defined(PETSC_HAVE_VIENNACL)
207:   PetscLogEventSetCollective(VEC_ViennaCLCopyToGPU,   PETSC_FALSE);
208:   PetscLogEventSetCollective(VEC_ViennaCLCopyFromGPU, PETSC_FALSE);
209: #endif
210: #if defined(PETSC_HAVE_CUDA)
211:   PetscLogEventSetCollective(VEC_CUDACopyToGPU,       PETSC_FALSE);
212:   PetscLogEventSetCollective(VEC_CUDACopyFromGPU,     PETSC_FALSE);
213:   PetscLogEventSetCollective(VEC_CUDACopyToGPUSome,   PETSC_FALSE);
214:   PetscLogEventSetCollective(VEC_CUDACopyFromGPUSome, PETSC_FALSE);
215: #endif
216:   /* Turn off high traffic events by default */
217:   PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);

219:   /* Process info exclusions */
220:   PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);
221:   if (opt) {
222:     PetscStrInList("vec",logList,',',&pkg);
223:     if (pkg) {PetscInfoDeactivateClass(VEC_CLASSID);}
224:     if (pkg) {PetscInfoDeactivateClass(VEC_SCATTER_CLASSID);}
225:   }

227:   /* Process summary exclusions */
228:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
229:   if (opt) {
230:     PetscStrInList("vec",logList,',',&pkg);
231:     if (pkg) {PetscLogEventExcludeClass(VEC_CLASSID);}
232:     if (pkg) {PetscLogEventExcludeClass(VEC_SCATTER_CLASSID);}
233:   }

235:   /*
236:     Create the special MPI reduction operation that may be used by VecNorm/DotBegin()
237:   */
238:   MPI_Op_create(PetscSplitReduction_Local,1,&PetscSplitReduction_Op);
239:   MPI_Op_create(MPIU_MaxIndex_Local,2,&MPIU_MAXINDEX_OP);
240:   MPI_Op_create(MPIU_MinIndex_Local,2,&MPIU_MININDEX_OP);

242:   /* Register the different norm types for cached norms */
243:   for (i=0; i<4; i++) {
244:     PetscObjectComposedDataRegister(NormIds+i);
245:   }

247:   /* Register package finalizer */
248:   PetscRegisterFinalize(VecFinalizePackage);
249:   return(0);
250: }

252: /*@C
253:   VecFinalizePackage - This function finalizes everything in the Vec package. It is called
254:   from PetscFinalize().

256:   Level: developer

258: .seealso: PetscInitialize()
259: @*/
260: PetscErrorCode  VecFinalizePackage(void)
261: {

265:   PetscFunctionListDestroy(&VecList);
266:   PetscFunctionListDestroy(&VecScatterList);
267:   MPI_Op_free(&PetscSplitReduction_Op);
268:   MPI_Op_free(&MPIU_MAXINDEX_OP);
269:   MPI_Op_free(&MPIU_MININDEX_OP);
270:   if (Petsc_Reduction_keyval != MPI_KEYVAL_INVALID) {
271:     MPI_Comm_free_keyval(&Petsc_Reduction_keyval);
272:   }
273:   VecPackageInitialized = PETSC_FALSE;
274:   VecRegisterAllCalled  = PETSC_FALSE;
275:   return(0);
276: }

278: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
279: /*
280:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

282:   This one registers all the methods that are in the basic PETSc Vec library.

284:  */
285: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
286: {

290:   PetscSFInitializePackage();
291:   ISInitializePackage();
292:   AOInitializePackage();
293:   VecInitializePackage();
294:   PFInitializePackage();
295:   return(0);
296: }

298: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */