Actual source code: dlregisvec.c

petsc-3.12.1 2019-10-22
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 <petscsection.h>
  7:  #include <petscao.h>

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

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

 16:   Level: developer

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

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

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

 39:   Level: developer

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

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

 85: extern MPI_Op PetscSplitReduction_Op;

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

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

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

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

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

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

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

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

136: static PetscBool  VecPackageInitialized = PETSC_FALSE;

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

143:   Level: developer

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

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

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

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

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

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

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

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

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

257:   Level: developer

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

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

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

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

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

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

299: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */