Actual source code: dlregisvec.c

petsc-3.8.3 2017-12-09
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:   char           *className;
 47:   PetscBool      opt;

 51:   if (ISPackageInitialized) return(0);
 52:   ISPackageInitialized = PETSC_TRUE;
 53:   /* Register Constructors */
 54:   ISRegisterAll();
 55:   ISLocalToGlobalMappingRegisterAll();
 56:   /* Register Classes */
 57:   PetscClassIdRegister("Index Set",&IS_CLASSID);
 58:   PetscClassIdRegister("IS L to G Mapping",&IS_LTOGM_CLASSID);
 59:   PetscClassIdRegister("Section",&PETSC_SECTION_CLASSID);
 60:   PetscClassIdRegister("Section Symmetry",&PETSC_SECTION_SYM_CLASSID);

 62:   /* Process info exclusions */
 63:   PetscOptionsGetString(NULL,NULL, "-info_exclude", logList, 256, &opt);
 64:   if (opt) {
 65:     PetscStrstr(logList, "is", &className);
 66:     if (className) {
 67:       PetscInfoDeactivateClass(IS_CLASSID);
 68:       PetscInfoDeactivateClass(IS_LTOGM_CLASSID);
 69:     }
 70:   }
 71:   /* Process summary exclusions */
 72:   PetscOptionsGetString(NULL,NULL, "-log_exclude", logList, 256, &opt);
 73:   if (opt) {
 74:     PetscStrstr(logList, "is", &className);
 75:     if (className) {
 76:       PetscLogEventDeactivateClass(IS_CLASSID);
 77:       PetscLogEventDeactivateClass(IS_LTOGM_CLASSID);
 78:     }
 79:   }
 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() when using dynamic libraries, and on the first call to VecCreate()
140:   when using static libraries.

142:   Level: developer

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

156:   if (VecPackageInitialized) return(0);
157:   VecPackageInitialized = PETSC_TRUE;
158:   /* Register Classes */
159:   PetscClassIdRegister("Vector",&VEC_CLASSID);
160:   PetscClassIdRegister("Vector Scatter",&VEC_SCATTER_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_CUSP)
203:   PetscLogEventRegister("VecCUSPCopyTo",     VEC_CLASSID,&VEC_CUSPCopyToGPU);
204:   PetscLogEventRegister("VecCUSPCopyFrom",   VEC_CLASSID,&VEC_CUSPCopyFromGPU);
205:   PetscLogEventRegister("VecCopyToSome",     VEC_CLASSID,&VEC_CUSPCopyToGPUSome);
206:   PetscLogEventRegister("VecCopyFromSome",   VEC_CLASSID,&VEC_CUSPCopyFromGPUSome);
207: #elif defined(PETSC_HAVE_VIENNACL)
208:   PetscLogEventRegister("VecViennaCLCopyTo",     VEC_CLASSID,&VEC_ViennaCLCopyToGPU);
209:   PetscLogEventRegister("VecViennaCLCopyFrom",   VEC_CLASSID,&VEC_ViennaCLCopyFromGPU);
210: #elif defined(PETSC_HAVE_VECCUDA)
211:   PetscLogEventRegister("VecCUDACopyTo",     VEC_CLASSID,&VEC_CUDACopyToGPU);
212:   PetscLogEventRegister("VecCUDACopyFrom",   VEC_CLASSID,&VEC_CUDACopyFromGPU);
213:   PetscLogEventRegister("VecCopyToSome",     VEC_CLASSID,&VEC_CUDACopyToGPUSome);
214:   PetscLogEventRegister("VecCopyFromSome",   VEC_CLASSID,&VEC_CUDACopyFromGPUSome);
215: #endif
216:   /* Turn off high traffic events by default */
217:   PetscLogEventSetActiveAll(VEC_DotBarrier, PETSC_FALSE);
218:   PetscLogEventSetActiveAll(VEC_DotNormBarrier, PETSC_FALSE);
219:   PetscLogEventSetActiveAll(VEC_MDotBarrier, PETSC_FALSE);
220:   PetscLogEventSetActiveAll(VEC_NormBarrier, PETSC_FALSE);
221:   PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);
222:   PetscLogEventSetActiveAll(VEC_ScatterBarrier, PETSC_FALSE);
223:   PetscLogEventSetActiveAll(VEC_ReduceBarrier, PETSC_FALSE);
224:   /* Process info exclusions */
225:   PetscOptionsGetString(NULL,NULL, "-info_exclude", logList, 256, &opt);
226:   if (opt) {
227:     PetscStrstr(logList, "vec", &className);
228:     if (className) {
229:       PetscInfoDeactivateClass(VEC_CLASSID);
230:     }
231:   }
232:   /* Process summary exclusions */
233:   PetscOptionsGetString(NULL,NULL, "-log_exclude", logList, 256, &opt);
234:   if (opt) {
235:     PetscStrstr(logList, "vec", &className);
236:     if (className) {
237:       PetscLogEventDeactivateClass(VEC_CLASSID);
238:     }
239:   }
240:   /* Special processing */
241:   opt  = PETSC_FALSE;
242:   PetscOptionsGetBool(NULL,NULL, "-log_sync", &opt,NULL);
243:   if (opt) {
244:     PetscLogEventSetActiveAll(VEC_ScatterBarrier, PETSC_TRUE);
245:     PetscLogEventSetActiveAll(VEC_NormBarrier, PETSC_TRUE);
246:     PetscLogEventSetActiveAll(VEC_DotBarrier, PETSC_TRUE);
247:     PetscLogEventSetActiveAll(VEC_DotNormBarrier, PETSC_TRUE);
248:     PetscLogEventSetActiveAll(VEC_MDotBarrier, PETSC_TRUE);
249:     PetscLogEventSetActiveAll(VEC_ReduceBarrier, PETSC_TRUE);
250:   }

252:   /*
253:     Create the special MPI reduction operation that may be used by VecNorm/DotBegin()
254:   */
255:   MPI_Op_create(PetscSplitReduction_Local,1,&PetscSplitReduction_Op);
256:   MPI_Op_create(MPIU_MaxIndex_Local,2,&MPIU_MAXINDEX_OP);
257:   MPI_Op_create(MPIU_MinIndex_Local,2,&MPIU_MININDEX_OP);

259:   /* Register the different norm types for cached norms */
260:   for (i=0; i<4; i++) {
261:     PetscObjectComposedDataRegister(NormIds+i);
262:   }

264:   /* Register finalization routine */
265:   PetscRegisterFinalize(VecFinalizePackage);
266:   return(0);
267: }

269: /*@C
270:   VecFinalizePackage - This function finalizes everything in the Vec package. It is called
271:   from PetscFinalize().

273:   Level: developer

275: .keywords: Vec, initialize, package
276: .seealso: PetscInitialize()
277: @*/
278: PetscErrorCode  VecFinalizePackage(void)
279: {

283:   PetscFunctionListDestroy(&VecList);
284:   MPI_Op_free(&PetscSplitReduction_Op);
285:   MPI_Op_free(&MPIU_MAXINDEX_OP);
286:   MPI_Op_free(&MPIU_MININDEX_OP);
287:   if (Petsc_Reduction_keyval != MPI_KEYVAL_INVALID) {
288:     MPI_Keyval_free(&Petsc_Reduction_keyval);
289:   }
290:   VecPackageInitialized = PETSC_FALSE;
291:   VecRegisterAllCalled  = PETSC_FALSE;
292:   return(0);
293: }

295: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
296: /*
297:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

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

301:  */
302: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
303: {

307:   PetscSFInitializePackage();
308:   ISInitializePackage();
309:   AOInitializePackage();
310:   VecInitializePackage();
311:   PFInitializePackage();
312:   return(0);
313: }

315: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */