Actual source code: dlregisvec.c

petsc-3.9.0 2018-04-07
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: .keywords: Petsc, destroy, package
 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:   return(0);
 31: }

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

 38:   Level: developer

 40: .keywords: Vec, initialize, package
 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) {PetscLogEventDeactivateClass(IS_CLASSID);}
 75:     if (pkg) {PetscLogEventDeactivateClass(IS_LTOGM_CLASSID);}
 76:     PetscStrInList("section",logList,',',&pkg);
 77:     if (pkg) {PetscLogEventDeactivateClass(PETSC_SECTION_CLASSID);}
 78:     if (pkg) {PetscLogEventDeactivateClass(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() when using dynamic libraries, and on the first call to VecCreate()
141:   when using static libraries.

143:   Level: developer

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

156:   if (VecPackageInitialized) return(0);
157:   VecPackageInitialized = PETSC_TRUE;
158:   /* Register Classes */
159:   PetscClassIdRegister("Vector",&VEC_CLASSID);

161:   /* Register Constructors */
162:   VecRegisterAll();
163:   /* Register Events */
164:   PetscLogEventRegister("VecView",          VEC_CLASSID,&VEC_View);
165:   PetscLogEventRegister("VecMax",           VEC_CLASSID,&VEC_Max);
166:   PetscLogEventRegister("VecMin",           VEC_CLASSID,&VEC_Min);
167:   PetscLogEventRegister("VecDotBarrier",    VEC_CLASSID,&VEC_DotBarrier);
168:   PetscLogEventRegister("VecDot",           VEC_CLASSID,&VEC_Dot);
169:   PetscLogEventRegister("VecDotNormBarr",   VEC_CLASSID,&VEC_DotNormBarrier);
170:   PetscLogEventRegister("VecDotNorm2",      VEC_CLASSID,&VEC_DotNorm);
171:   PetscLogEventRegister("VecMDotBarrier",   VEC_CLASSID,&VEC_MDotBarrier);
172:   PetscLogEventRegister("VecMDot",          VEC_CLASSID,&VEC_MDot);
173:   PetscLogEventRegister("VecTDot",          VEC_CLASSID,&VEC_TDot);
174:   PetscLogEventRegister("VecMTDot",         VEC_CLASSID,&VEC_MTDot);
175:   PetscLogEventRegister("VecNormBarrier",   VEC_CLASSID,&VEC_NormBarrier);
176:   PetscLogEventRegister("VecNorm",          VEC_CLASSID,&VEC_Norm);
177:   PetscLogEventRegister("VecScale",         VEC_CLASSID,&VEC_Scale);
178:   PetscLogEventRegister("VecCopy",          VEC_CLASSID,&VEC_Copy);
179:   PetscLogEventRegister("VecSet",           VEC_CLASSID,&VEC_Set);
180:   PetscLogEventRegister("VecAXPY",          VEC_CLASSID,&VEC_AXPY);
181:   PetscLogEventRegister("VecAYPX",          VEC_CLASSID,&VEC_AYPX);
182:   PetscLogEventRegister("VecAXPBYCZ",       VEC_CLASSID,&VEC_AXPBYPCZ);
183:   PetscLogEventRegister("VecWAXPY",         VEC_CLASSID,&VEC_WAXPY);
184:   PetscLogEventRegister("VecMAXPY",         VEC_CLASSID,&VEC_MAXPY);
185:   PetscLogEventRegister("VecSwap",          VEC_CLASSID,&VEC_Swap);
186:   PetscLogEventRegister("VecOps",           VEC_CLASSID,&VEC_Ops);
187:   PetscLogEventRegister("VecAssemblyBegin", VEC_CLASSID,&VEC_AssemblyBegin);
188:   PetscLogEventRegister("VecAssemblyEnd",   VEC_CLASSID,&VEC_AssemblyEnd);
189:   PetscLogEventRegister("VecPointwiseMult", VEC_CLASSID,&VEC_PointwiseMult);
190:   PetscLogEventRegister("VecSetValues",     VEC_CLASSID,&VEC_SetValues);
191:   PetscLogEventRegister("VecLoad",          VEC_CLASSID,&VEC_Load);
192:   PetscLogEventRegister("VecScatterBarrie", VEC_CLASSID,&VEC_ScatterBarrier);
193:   PetscLogEventRegister("VecScatterBegin",  VEC_CLASSID,&VEC_ScatterBegin);
194:   PetscLogEventRegister("VecScatterEnd  ",    VEC_CLASSID,&VEC_ScatterEnd);
195:   PetscLogEventRegister("VecSetRandom",     VEC_CLASSID,&VEC_SetRandom);
196:   PetscLogEventRegister("VecReduceArith",   VEC_CLASSID,&VEC_ReduceArithmetic);
197:   PetscLogEventRegister("VecReduceBarrier", VEC_CLASSID,&VEC_ReduceBarrier);
198:   PetscLogEventRegister("VecReduceComm",    VEC_CLASSID,&VEC_ReduceCommunication); /* must follow barrier */
199:   PetscLogEventRegister("VecReduceBegin",   VEC_CLASSID,&VEC_ReduceBegin);
200:   PetscLogEventRegister("VecReduceEnd",     VEC_CLASSID,&VEC_ReduceEnd);
201:   PetscLogEventRegister("VecNormalize",     VEC_CLASSID,&VEC_Normalize);
202: #if defined(PETSC_HAVE_VIENNACL)
203:   PetscLogEventRegister("VecViennaCLCopyTo",     VEC_CLASSID,&VEC_ViennaCLCopyToGPU);
204:   PetscLogEventRegister("VecViennaCLCopyFrom",   VEC_CLASSID,&VEC_ViennaCLCopyFromGPU);
205: #endif
206: #if defined(PETSC_HAVE_VECCUDA)
207:   PetscLogEventRegister("VecCUDACopyTo",     VEC_CLASSID,&VEC_CUDACopyToGPU);
208:   PetscLogEventRegister("VecCUDACopyFrom",   VEC_CLASSID,&VEC_CUDACopyFromGPU);
209:   PetscLogEventRegister("VecCopyToSome",     VEC_CLASSID,&VEC_CUDACopyToGPUSome);
210:   PetscLogEventRegister("VecCopyFromSome",   VEC_CLASSID,&VEC_CUDACopyFromGPUSome);
211: #endif
212:   /* Turn off high traffic events by default */
213:   PetscLogEventSetActiveAll(VEC_DotBarrier, PETSC_FALSE);
214:   PetscLogEventSetActiveAll(VEC_DotNormBarrier, PETSC_FALSE);
215:   PetscLogEventSetActiveAll(VEC_MDotBarrier, PETSC_FALSE);
216:   PetscLogEventSetActiveAll(VEC_NormBarrier, PETSC_FALSE);
217:   PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);
218:   PetscLogEventSetActiveAll(VEC_ScatterBarrier, PETSC_FALSE);
219:   PetscLogEventSetActiveAll(VEC_ReduceBarrier, 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:   }
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) {PetscLogEventDeactivateClass(VEC_CLASSID);}
232:     if (pkg) {PetscLogEventDeactivateClass(VEC_SCATTER_CLASSID);}
233:   }
234:   /* Special processing */
235:   opt  = PETSC_FALSE;
236:   PetscOptionsGetBool(NULL,NULL, "-log_sync", &opt,NULL);
237:   if (opt) {
238:     PetscLogEventSetActiveAll(VEC_ScatterBarrier, PETSC_TRUE);
239:     PetscLogEventSetActiveAll(VEC_NormBarrier, PETSC_TRUE);
240:     PetscLogEventSetActiveAll(VEC_DotBarrier, PETSC_TRUE);
241:     PetscLogEventSetActiveAll(VEC_DotNormBarrier, PETSC_TRUE);
242:     PetscLogEventSetActiveAll(VEC_MDotBarrier, PETSC_TRUE);
243:     PetscLogEventSetActiveAll(VEC_ReduceBarrier, PETSC_TRUE);
244:   }

246:   /*
247:     Create the special MPI reduction operation that may be used by VecNorm/DotBegin()
248:   */
249:   MPI_Op_create(PetscSplitReduction_Local,1,&PetscSplitReduction_Op);
250:   MPI_Op_create(MPIU_MaxIndex_Local,2,&MPIU_MAXINDEX_OP);
251:   MPI_Op_create(MPIU_MinIndex_Local,2,&MPIU_MININDEX_OP);

253:   /* Register the different norm types for cached norms */
254:   for (i=0; i<4; i++) {
255:     PetscObjectComposedDataRegister(NormIds+i);
256:   }

258:   /* Register package finalizer */
259:   PetscRegisterFinalize(VecFinalizePackage);
260:   return(0);
261: }

263: /*@C
264:   VecFinalizePackage - This function finalizes everything in the Vec package. It is called
265:   from PetscFinalize().

267:   Level: developer

269: .keywords: Vec, initialize, package
270: .seealso: PetscInitialize()
271: @*/
272: PetscErrorCode  VecFinalizePackage(void)
273: {

277:   PetscFunctionListDestroy(&VecList);
278:   MPI_Op_free(&PetscSplitReduction_Op);
279:   MPI_Op_free(&MPIU_MAXINDEX_OP);
280:   MPI_Op_free(&MPIU_MININDEX_OP);
281:   if (Petsc_Reduction_keyval != MPI_KEYVAL_INVALID) {
282:     MPI_Comm_free_keyval(&Petsc_Reduction_keyval);
283:   }
284:   VecPackageInitialized = PETSC_FALSE;
285:   VecRegisterAllCalled  = PETSC_FALSE;
286:   return(0);
287: }

289: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
290: /*
291:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

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

295:  */
296: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
297: {

301:   PetscSFInitializePackage();
302:   ISInitializePackage();
303:   AOInitializePackage();
304:   VecInitializePackage();
305:   PFInitializePackage();
306:   return(0);
307: }

309: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */