Actual source code: dlregisvec.c
petsc-3.10.3 2018-12-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: .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) {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() 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);
    160:   /* Register Constructors */
    161:   VecRegisterAll();
    162:   /* Register Events */
    163:   PetscLogEventRegister("VecView",          VEC_CLASSID,&VEC_View);
    164:   PetscLogEventRegister("VecMax",           VEC_CLASSID,&VEC_Max);
    165:   PetscLogEventRegister("VecMin",           VEC_CLASSID,&VEC_Min);
    166:   PetscLogEventRegister("VecDot",           VEC_CLASSID,&VEC_Dot);
    167:   PetscLogEventRegister("VecDotNorm2",      VEC_CLASSID,&VEC_DotNorm2);
    168:   PetscLogEventRegister("VecMDot",          VEC_CLASSID,&VEC_MDot);
    169:   PetscLogEventRegister("VecTDot",          VEC_CLASSID,&VEC_TDot);
    170:   PetscLogEventRegister("VecMTDot",         VEC_CLASSID,&VEC_MTDot);
    171:   PetscLogEventRegister("VecNorm",          VEC_CLASSID,&VEC_Norm);
    172:   PetscLogEventRegister("VecScale",         VEC_CLASSID,&VEC_Scale);
    173:   PetscLogEventRegister("VecCopy",          VEC_CLASSID,&VEC_Copy);
    174:   PetscLogEventRegister("VecSet",           VEC_CLASSID,&VEC_Set);
    175:   PetscLogEventRegister("VecAXPY",          VEC_CLASSID,&VEC_AXPY);
    176:   PetscLogEventRegister("VecAYPX",          VEC_CLASSID,&VEC_AYPX);
    177:   PetscLogEventRegister("VecAXPBYCZ",       VEC_CLASSID,&VEC_AXPBYPCZ);
    178:   PetscLogEventRegister("VecWAXPY",         VEC_CLASSID,&VEC_WAXPY);
    179:   PetscLogEventRegister("VecMAXPY",         VEC_CLASSID,&VEC_MAXPY);
    180:   PetscLogEventRegister("VecSwap",          VEC_CLASSID,&VEC_Swap);
    181:   PetscLogEventRegister("VecOps",           VEC_CLASSID,&VEC_Ops);
    182:   PetscLogEventRegister("VecAssemblyBegin", VEC_CLASSID,&VEC_AssemblyBegin);
    183:   PetscLogEventRegister("VecAssemblyEnd",   VEC_CLASSID,&VEC_AssemblyEnd);
    184:   PetscLogEventRegister("VecPointwiseMult", VEC_CLASSID,&VEC_PointwiseMult);
    185:   PetscLogEventRegister("VecSetValues",     VEC_CLASSID,&VEC_SetValues);
    186:   PetscLogEventRegister("VecLoad",          VEC_CLASSID,&VEC_Load);
    187:   PetscLogEventRegister("VecScatterBegin",  VEC_CLASSID,&VEC_ScatterBegin);
    188:   PetscLogEventRegister("VecScatterEnd  ",  VEC_CLASSID,&VEC_ScatterEnd);
    189:   PetscLogEventRegister("VecSetRandom",     VEC_CLASSID,&VEC_SetRandom);
    190:   PetscLogEventRegister("VecReduceArith",   VEC_CLASSID,&VEC_ReduceArithmetic);
    191:   PetscLogEventRegister("VecReduceComm",    VEC_CLASSID,&VEC_ReduceCommunication);
    192:   PetscLogEventRegister("VecReduceBegin",   VEC_CLASSID,&VEC_ReduceBegin);
    193:   PetscLogEventRegister("VecReduceEnd",     VEC_CLASSID,&VEC_ReduceEnd);
    194:   PetscLogEventRegister("VecNormalize",     VEC_CLASSID,&VEC_Normalize);
    195: #if defined(PETSC_HAVE_VIENNACL)
    196:   PetscLogEventRegister("VecViennaCLCopyTo",   VEC_CLASSID,&VEC_ViennaCLCopyToGPU);
    197:   PetscLogEventRegister("VecViennaCLCopyFrom", VEC_CLASSID,&VEC_ViennaCLCopyFromGPU);
    198: #endif
    199: #if defined(PETSC_HAVE_VECCUDA)
    200:   PetscLogEventRegister("VecCUDACopyTo",     VEC_CLASSID,&VEC_CUDACopyToGPU);
    201:   PetscLogEventRegister("VecCUDACopyFrom",   VEC_CLASSID,&VEC_CUDACopyFromGPU);
    202:   PetscLogEventRegister("VecCopyToSome",     VEC_CLASSID,&VEC_CUDACopyToGPUSome);
    203:   PetscLogEventRegister("VecCopyFromSome",   VEC_CLASSID,&VEC_CUDACopyFromGPUSome);
    204: #endif

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

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

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

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

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

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

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

    258:   Level: developer

    260: .keywords: Vec, initialize, package
    261: .seealso: PetscInitialize()
    262: @*/
    263: PetscErrorCode  VecFinalizePackage(void)
    264: {

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

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

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

    287:  */
    288: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
    289: {

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

    301: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */