Actual source code: dlregisvec.c
petsc-3.10.5 2019-03-28
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:   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() when using dynamic libraries, and on the first call to ISCreateXXXX()
     37:   when using static libraries.

     39:   Level: developer

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

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

     86: extern MPI_Op PetscSplitReduction_Op;

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

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

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

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

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

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

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

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

    137: static PetscBool  VecPackageInitialized = PETSC_FALSE;

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

    144:   Level: developer

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

    157:   if (VecPackageInitialized) return(0);
    158:   VecPackageInitialized = PETSC_TRUE;
    159:   /* Register Classes */
    160:   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("VecDot",           VEC_CLASSID,&VEC_Dot);
    168:   PetscLogEventRegister("VecDotNorm2",      VEC_CLASSID,&VEC_DotNorm2);
    169:   PetscLogEventRegister("VecMDot",          VEC_CLASSID,&VEC_MDot);
    170:   PetscLogEventRegister("VecTDot",          VEC_CLASSID,&VEC_TDot);
    171:   PetscLogEventRegister("VecMTDot",         VEC_CLASSID,&VEC_MTDot);
    172:   PetscLogEventRegister("VecNorm",          VEC_CLASSID,&VEC_Norm);
    173:   PetscLogEventRegister("VecScale",         VEC_CLASSID,&VEC_Scale);
    174:   PetscLogEventRegister("VecCopy",          VEC_CLASSID,&VEC_Copy);
    175:   PetscLogEventRegister("VecSet",           VEC_CLASSID,&VEC_Set);
    176:   PetscLogEventRegister("VecAXPY",          VEC_CLASSID,&VEC_AXPY);
    177:   PetscLogEventRegister("VecAYPX",          VEC_CLASSID,&VEC_AYPX);
    178:   PetscLogEventRegister("VecAXPBYCZ",       VEC_CLASSID,&VEC_AXPBYPCZ);
    179:   PetscLogEventRegister("VecWAXPY",         VEC_CLASSID,&VEC_WAXPY);
    180:   PetscLogEventRegister("VecMAXPY",         VEC_CLASSID,&VEC_MAXPY);
    181:   PetscLogEventRegister("VecSwap",          VEC_CLASSID,&VEC_Swap);
    182:   PetscLogEventRegister("VecOps",           VEC_CLASSID,&VEC_Ops);
    183:   PetscLogEventRegister("VecAssemblyBegin", VEC_CLASSID,&VEC_AssemblyBegin);
    184:   PetscLogEventRegister("VecAssemblyEnd",   VEC_CLASSID,&VEC_AssemblyEnd);
    185:   PetscLogEventRegister("VecPointwiseMult", VEC_CLASSID,&VEC_PointwiseMult);
    186:   PetscLogEventRegister("VecSetValues",     VEC_CLASSID,&VEC_SetValues);
    187:   PetscLogEventRegister("VecLoad",          VEC_CLASSID,&VEC_Load);
    188:   PetscLogEventRegister("VecScatterBegin",  VEC_CLASSID,&VEC_ScatterBegin);
    189:   PetscLogEventRegister("VecScatterEnd  ",  VEC_CLASSID,&VEC_ScatterEnd);
    190:   PetscLogEventRegister("VecSetRandom",     VEC_CLASSID,&VEC_SetRandom);
    191:   PetscLogEventRegister("VecReduceArith",   VEC_CLASSID,&VEC_ReduceArithmetic);
    192:   PetscLogEventRegister("VecReduceComm",    VEC_CLASSID,&VEC_ReduceCommunication);
    193:   PetscLogEventRegister("VecReduceBegin",   VEC_CLASSID,&VEC_ReduceBegin);
    194:   PetscLogEventRegister("VecReduceEnd",     VEC_CLASSID,&VEC_ReduceEnd);
    195:   PetscLogEventRegister("VecNormalize",     VEC_CLASSID,&VEC_Normalize);
    196: #if defined(PETSC_HAVE_VIENNACL)
    197:   PetscLogEventRegister("VecViennaCLCopyTo",   VEC_CLASSID,&VEC_ViennaCLCopyToGPU);
    198:   PetscLogEventRegister("VecViennaCLCopyFrom", VEC_CLASSID,&VEC_ViennaCLCopyFromGPU);
    199: #endif
    200: #if defined(PETSC_HAVE_VECCUDA)
    201:   PetscLogEventRegister("VecCUDACopyTo",     VEC_CLASSID,&VEC_CUDACopyToGPU);
    202:   PetscLogEventRegister("VecCUDACopyFrom",   VEC_CLASSID,&VEC_CUDACopyFromGPU);
    203:   PetscLogEventRegister("VecCopyToSome",     VEC_CLASSID,&VEC_CUDACopyToGPUSome);
    204:   PetscLogEventRegister("VecCopyFromSome",   VEC_CLASSID,&VEC_CUDACopyFromGPUSome);
    205: #endif

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

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

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

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

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

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

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

    259:   Level: developer

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

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

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

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

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

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

    302: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */