/*@C TSRKInitializePackage - This function initializes everything in the TSRK package. It is called from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to TSCreate_RK() when using static libraries. Level: developer .keywords: TS, TSRK, initialize, package .seealso: PetscInitialize() @*/ PetscErrorCode TSRKInitializePackage(void) { PetscErrorCode ierr; PetscFunctionBegin; if (TSRKPackageInitialized) PetscFunctionReturn(0); TSRKPackageInitialized = PETSC_TRUE; ierr = TSRKRegisterAll();CHKERRQ(ierr); ierr = PetscObjectComposedDataRegister(&explicit_stage_time_id);CHKERRQ(ierr); ierr = PetscRegisterFinalize(TSRKFinalizePackage);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PCInitializePackage - This function initializes everything in the PC package. It is called from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to PCCreate() when using static libraries. Level: developer .keywords: PC, initialize, package .seealso: PetscInitialize() @*/ PetscErrorCode PCInitializePackage(void) { char logList[256]; char *className; PetscBool opt; PetscErrorCode ierr; PetscFunctionBegin; if (PCPackageInitialized) PetscFunctionReturn(0); PCPackageInitialized = PETSC_TRUE; /* Initialize subpackages */ ierr = PCGAMGInitializePackage();CHKERRQ(ierr); /* Register Classes */ ierr = PetscClassIdRegister("Preconditioner",&PC_CLASSID);CHKERRQ(ierr); /* Register Constructors */ ierr = PCRegisterAll();CHKERRQ(ierr); /* Register Events */ ierr = PetscLogEventRegister("PCSetUp", PC_CLASSID,&PC_SetUp);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCSetUpOnBlocks", PC_CLASSID,&PC_SetUpOnBlocks);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCApplyOnBlocks", PC_CLASSID,&PC_ApplyOnBlocks);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCApplyOnMproc", PC_CLASSID,&PC_ApplyOnMproc);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCApply", PC_CLASSID,&PC_Apply);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCApplyCoarse", PC_CLASSID,&PC_ApplyCoarse);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCApplyMultiple", PC_CLASSID,&PC_ApplyMultiple);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCApplySymmLeft", PC_CLASSID,&PC_ApplySymmetricLeft);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCApplySymmRight", PC_CLASSID,&PC_ApplySymmetricRight);CHKERRQ(ierr); ierr = PetscLogEventRegister("PCModifySubMatri", PC_CLASSID,&PC_ModifySubMatrices);CHKERRQ(ierr); /* Process info exclusions */ ierr = PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); if (opt) { ierr = PetscStrstr(logList, "pc", &className);CHKERRQ(ierr); if (className) { ierr = PetscInfoDeactivateClass(PC_CLASSID);CHKERRQ(ierr); } } /* Process summary exclusions */ ierr = PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); if (opt) { ierr = PetscStrstr(logList, "pc", &className);CHKERRQ(ierr); if (className) { ierr = PetscLogEventDeactivateClass(PC_CLASSID);CHKERRQ(ierr); } } /* Register data */ ierr = PetscObjectComposedDataRegister(&PetscMGLevelId);CHKERRQ(ierr); ierr = PetscRegisterFinalize(PCFinalizePackage);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C VecInitializePackage - This function initializes everything in the Vec package. It is called from PetscDLLibraryRegister() when using dynamic libraries, and on the first call to VecCreate() when using static libraries. Level: developer .keywords: Vec, initialize, package .seealso: PetscInitialize() @*/ PetscErrorCode VecInitializePackage(void) { char logList[256]; char *className; PetscBool opt; PetscErrorCode ierr; PetscInt i; PetscFunctionBegin; if (VecPackageInitialized) PetscFunctionReturn(0); VecPackageInitialized = PETSC_TRUE; /* Register Classes */ ierr = PetscClassIdRegister("Vector",&VEC_CLASSID);CHKERRQ(ierr); ierr = PetscClassIdRegister("Vector Scatter",&VEC_SCATTER_CLASSID);CHKERRQ(ierr); /* Register Constructors */ ierr = VecRegisterAll();CHKERRQ(ierr); /* Register Events */ ierr = PetscLogEventRegister("VecView", VEC_CLASSID,&VEC_View);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecMax", VEC_CLASSID,&VEC_Max);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecMin", VEC_CLASSID,&VEC_Min);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecDotBarrier", VEC_CLASSID,&VEC_DotBarrier);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecDot", VEC_CLASSID,&VEC_Dot);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecDotNormBarr", VEC_CLASSID,&VEC_DotNormBarrier);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecDotNorm2", VEC_CLASSID,&VEC_DotNorm);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecMDotBarrier", VEC_CLASSID,&VEC_MDotBarrier);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecMDot", VEC_CLASSID,&VEC_MDot);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecTDot", VEC_CLASSID,&VEC_TDot);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecMTDot", VEC_CLASSID,&VEC_MTDot);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecNormBarrier", VEC_CLASSID,&VEC_NormBarrier);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecNorm", VEC_CLASSID,&VEC_Norm);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecScale", VEC_CLASSID,&VEC_Scale);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecCopy", VEC_CLASSID,&VEC_Copy);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecSet", VEC_CLASSID,&VEC_Set);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecAXPY", VEC_CLASSID,&VEC_AXPY);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecAYPX", VEC_CLASSID,&VEC_AYPX);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecAXPBYCZ", VEC_CLASSID,&VEC_AXPBYPCZ);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecWAXPY", VEC_CLASSID,&VEC_WAXPY);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecMAXPY", VEC_CLASSID,&VEC_MAXPY);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecSwap", VEC_CLASSID,&VEC_Swap);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecOps", VEC_CLASSID,&VEC_Ops);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecAssemblyBegin", VEC_CLASSID,&VEC_AssemblyBegin);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecAssemblyEnd", VEC_CLASSID,&VEC_AssemblyEnd);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecPointwiseMult", VEC_CLASSID,&VEC_PointwiseMult);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecSetValues", VEC_CLASSID,&VEC_SetValues);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecLoad", VEC_CLASSID,&VEC_Load);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecScatterBarrie", VEC_CLASSID,&VEC_ScatterBarrier);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecScatterBegin", VEC_CLASSID,&VEC_ScatterBegin);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecScatterEnd", VEC_CLASSID,&VEC_ScatterEnd);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecSetRandom", VEC_CLASSID,&VEC_SetRandom);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecReduceArith", VEC_CLASSID,&VEC_ReduceArithmetic);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecReduceBarrier", VEC_CLASSID,&VEC_ReduceBarrier);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecReduceComm", VEC_CLASSID,&VEC_ReduceCommunication);CHKERRQ(ierr); /* must follow barrier */ ierr = PetscLogEventRegister("VecReduceBegin", VEC_CLASSID,&VEC_ReduceBegin);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecReduceEnd", VEC_CLASSID,&VEC_ReduceEnd);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecNormalize", VEC_CLASSID,&VEC_Normalize);CHKERRQ(ierr); #if defined(PETSC_HAVE_CUSP) ierr = PetscLogEventRegister("VecCUSPCopyTo", VEC_CLASSID,&VEC_CUSPCopyToGPU);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecCUSPCopyFrom", VEC_CLASSID,&VEC_CUSPCopyFromGPU);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecCopyToSome", VEC_CLASSID,&VEC_CUSPCopyToGPUSome);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecCopyFromSome", VEC_CLASSID,&VEC_CUSPCopyFromGPUSome);CHKERRQ(ierr); #endif #if defined(PETSC_HAVE_VIENNACL) ierr = PetscLogEventRegister("VecViennaCLCopyTo", VEC_CLASSID,&VEC_ViennaCLCopyToGPU);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecViennaCLCopyFrom", VEC_CLASSID,&VEC_ViennaCLCopyFromGPU);CHKERRQ(ierr); #endif /* Turn off high traffic events by default */ ierr = PetscLogEventSetActiveAll(VEC_DotBarrier, PETSC_FALSE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_DotNormBarrier, PETSC_FALSE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_MDotBarrier, PETSC_FALSE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_NormBarrier, PETSC_FALSE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_ScatterBarrier, PETSC_FALSE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_ReduceBarrier, PETSC_FALSE);CHKERRQ(ierr); /* Process info exclusions */ ierr = PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); if (opt) { ierr = PetscStrstr(logList, "vec", &className);CHKERRQ(ierr); if (className) { ierr = PetscInfoDeactivateClass(VEC_CLASSID);CHKERRQ(ierr); } } /* Process summary exclusions */ ierr = PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); if (opt) { ierr = PetscStrstr(logList, "vec", &className);CHKERRQ(ierr); if (className) { ierr = PetscLogEventDeactivateClass(VEC_CLASSID);CHKERRQ(ierr); } } /* Special processing */ opt = PETSC_FALSE; ierr = PetscOptionsGetBool(NULL, "-log_sync", &opt,NULL);CHKERRQ(ierr); if (opt) { ierr = PetscLogEventSetActiveAll(VEC_ScatterBarrier, PETSC_TRUE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_NormBarrier, PETSC_TRUE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_DotBarrier, PETSC_TRUE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_DotNormBarrier, PETSC_TRUE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_MDotBarrier, PETSC_TRUE);CHKERRQ(ierr); ierr = PetscLogEventSetActiveAll(VEC_ReduceBarrier, PETSC_TRUE);CHKERRQ(ierr); } /* Create the special MPI reduction operation that may be used by VecNorm/DotBegin() */ ierr = MPI_Op_create(PetscSplitReduction_Local,1,&PetscSplitReduction_Op);CHKERRQ(ierr); ierr = MPI_Op_create(VecMax_Local,2,&VecMax_Local_Op);CHKERRQ(ierr); ierr = MPI_Op_create(VecMin_Local,2,&VecMin_Local_Op);CHKERRQ(ierr); /* Register the different norm types for cached norms */ for (i=0; i<4; i++) { ierr = PetscObjectComposedDataRegister(NormIds+i);CHKERRQ(ierr); } /* Register finalization routine */ ierr = PetscRegisterFinalize(VecFinalizePackage);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode VecView_Seq_ASCII(Vec xin,PetscViewer viewer) { PetscErrorCode ierr; PetscInt i,n = xin->map->n; const char *name; PetscViewerFormat format; const PetscScalar *xv; PetscFunctionBegin; ierr = VecGetArrayRead(xin,&xv);CHKERRQ(ierr); ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); if (format == PETSC_VIEWER_ASCII_MATLAB) { ierr = PetscObjectGetName((PetscObject)xin,&name);CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(viewer,"%s = [\n",name);CHKERRQ(ierr); for (i=0; i<n; i++) { #if defined(PETSC_USE_COMPLEX) if (PetscImaginaryPart(xv[i]) > 0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%18.16e + %18.16ei\n",(double)PetscRealPart(xv[i]),(double)PetscImaginaryPart(xv[i]));CHKERRQ(ierr); } else if (PetscImaginaryPart(xv[i]) < 0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%18.16e - %18.16ei\n",(double)PetscRealPart(xv[i]),-(double)PetscImaginaryPart(xv[i]));CHKERRQ(ierr); } else { ierr = PetscViewerASCIIPrintf(viewer,"%18.16e\n",(double)PetscRealPart(xv[i]));CHKERRQ(ierr); } #else ierr = PetscViewerASCIIPrintf(viewer,"%18.16e\n",(double) xv[i]);CHKERRQ(ierr); #endif } ierr = PetscViewerASCIIPrintf(viewer,"];\n");CHKERRQ(ierr); } else if (format == PETSC_VIEWER_ASCII_SYMMODU) { for (i=0; i<n; i++) { #if defined(PETSC_USE_COMPLEX) ierr = PetscViewerASCIIPrintf(viewer,"%18.16e %18.16e\n",(double)PetscRealPart(xv[i]),(double)PetscImaginaryPart(xv[i]));CHKERRQ(ierr); #else ierr = PetscViewerASCIIPrintf(viewer,"%18.16e\n",(double)xv[i]);CHKERRQ(ierr); #endif } } else if (format == PETSC_VIEWER_ASCII_VTK || format == PETSC_VIEWER_ASCII_VTK_CELL) { /* state 0: No header has been output state 1: Only POINT_DATA has been output state 2: Only CELL_DATA has been output state 3: Output both, POINT_DATA last state 4: Output both, CELL_DATA last */ static PetscInt stateId = -1; int outputState = 0; PetscBool hasState; int doOutput = 0; PetscInt bs, b; if (stateId < 0) { ierr = PetscObjectComposedDataRegister(&stateId);CHKERRQ(ierr); } ierr = PetscObjectComposedDataGetInt((PetscObject) viewer, stateId, outputState, hasState);CHKERRQ(ierr); if (!hasState) outputState = 0; ierr = PetscObjectGetName((PetscObject) xin, &name);CHKERRQ(ierr); ierr = VecGetBlockSize(xin, &bs);CHKERRQ(ierr); if ((bs < 1) || (bs > 3)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "VTK can only handle 3D objects, but vector dimension is %d", bs); if (format == PETSC_VIEWER_ASCII_VTK) { if (outputState == 0) { outputState = 1; doOutput = 1; } else if (outputState == 1) doOutput = 0; else if (outputState == 2) { outputState = 3; doOutput = 1; } else if (outputState == 3) doOutput = 0; else if (outputState == 4) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "Tried to output POINT_DATA again after intervening CELL_DATA"); if (doOutput) { ierr = PetscViewerASCIIPrintf(viewer, "POINT_DATA %d\n", n/bs);CHKERRQ(ierr); } } else { if (outputState == 0) { outputState = 2; doOutput = 1; } else if (outputState == 1) { outputState = 4; doOutput = 1; } else if (outputState == 2) doOutput = 0; else if (outputState == 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "Tried to output CELL_DATA again after intervening POINT_DATA"); else if (outputState == 4) doOutput = 0; if (doOutput) { ierr = PetscViewerASCIIPrintf(viewer, "CELL_DATA %d\n", n);CHKERRQ(ierr); } } ierr = PetscObjectComposedDataSetInt((PetscObject) viewer, stateId, outputState);CHKERRQ(ierr); if (name) { if (bs == 3) { ierr = PetscViewerASCIIPrintf(viewer, "VECTORS %s double\n", name);CHKERRQ(ierr); } else { ierr = PetscViewerASCIIPrintf(viewer, "SCALARS %s double %d\n", name, bs);CHKERRQ(ierr); } } else { ierr = PetscViewerASCIIPrintf(viewer, "SCALARS scalars double %d\n", bs);CHKERRQ(ierr); } if (bs != 3) { ierr = PetscViewerASCIIPrintf(viewer, "LOOKUP_TABLE default\n");CHKERRQ(ierr); } for (i=0; i<n/bs; i++) { for (b=0; b<bs; b++) { if (b > 0) { ierr = PetscViewerASCIIPrintf(viewer," ");CHKERRQ(ierr); } #if !defined(PETSC_USE_COMPLEX) ierr = PetscViewerASCIIPrintf(viewer,"%g",(double)xv[i*bs+b]);CHKERRQ(ierr); #endif } ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr); } } else if (format == PETSC_VIEWER_ASCII_VTK_COORDS) { PetscInt bs, b; ierr = VecGetBlockSize(xin, &bs);CHKERRQ(ierr); if ((bs < 1) || (bs > 3)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "VTK can only handle 3D objects, but vector dimension is %d", bs); for (i=0; i<n/bs; i++) { for (b=0; b<bs; b++) { if (b > 0) { ierr = PetscViewerASCIIPrintf(viewer," ");CHKERRQ(ierr); } #if !defined(PETSC_USE_COMPLEX) ierr = PetscViewerASCIIPrintf(viewer,"%g",(double)xv[i*bs+b]);CHKERRQ(ierr); #endif } for (b=bs; b<3; b++) { ierr = PetscViewerASCIIPrintf(viewer," 0.0");CHKERRQ(ierr); } ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr); } } else if (format == PETSC_VIEWER_ASCII_PCICE) { PetscInt bs, b; ierr = VecGetBlockSize(xin, &bs);CHKERRQ(ierr); if ((bs < 1) || (bs > 3)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "PCICE can only handle up to 3D objects, but vector dimension is %d", bs); ierr = PetscViewerASCIIPrintf(viewer,"%D\n", xin->map->N/bs);CHKERRQ(ierr); for (i=0; i<n/bs; i++) { ierr = PetscViewerASCIIPrintf(viewer,"%7D ", i+1);CHKERRQ(ierr); for (b=0; b<bs; b++) { if (b > 0) { ierr = PetscViewerASCIIPrintf(viewer," ");CHKERRQ(ierr); } #if !defined(PETSC_USE_COMPLEX) ierr = PetscViewerASCIIPrintf(viewer,"% 12.5E",(double)xv[i*bs+b]);CHKERRQ(ierr); #endif } ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr); } } else if (format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { /* No info */ } else { for (i=0; i<n; i++) { if (format == PETSC_VIEWER_ASCII_INDEX) { ierr = PetscViewerASCIIPrintf(viewer,"%D: ",i);CHKERRQ(ierr); } #if defined(PETSC_USE_COMPLEX) if (PetscImaginaryPart(xv[i]) > 0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%g + %g i\n",(double)PetscRealPart(xv[i]),(double)PetscImaginaryPart(xv[i]));CHKERRQ(ierr); } else if (PetscImaginaryPart(xv[i]) < 0.0) { ierr = PetscViewerASCIIPrintf(viewer,"%g - %g i\n",(double)PetscRealPart(xv[i]),-(double)PetscImaginaryPart(xv[i]));CHKERRQ(ierr); } else { ierr = PetscViewerASCIIPrintf(viewer,"%g\n",(double)PetscRealPart(xv[i]));CHKERRQ(ierr); } #else ierr = PetscViewerASCIIPrintf(viewer,"%g\n",(double)xv[i]);CHKERRQ(ierr); #endif } } ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); ierr = VecRestoreArrayRead(xin,&xv);CHKERRQ(ierr); PetscFunctionReturn(0); }