1*4c02969dSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscsys.h" I*/ 2*4c02969dSBarry Smith #include <adios.h> 3*4c02969dSBarry Smith 4*4c02969dSBarry Smith typedef struct GroupList { 5*4c02969dSBarry Smith const char *name; 6*4c02969dSBarry Smith struct GroupList *next; 7*4c02969dSBarry Smith } GroupList; 8*4c02969dSBarry Smith 9*4c02969dSBarry Smith typedef struct { 10*4c02969dSBarry Smith char *filename; 11*4c02969dSBarry Smith PetscFileMode btype; 12*4c02969dSBarry Smith PetscInt timestep; 13*4c02969dSBarry Smith GroupList *groups; 14*4c02969dSBarry Smith } PetscViewer_ADIOS; 15*4c02969dSBarry Smith 16*4c02969dSBarry Smith static PetscErrorCode PetscViewerSetFromOptions_ADIOS(PetscOptionItems *PetscOptionsObject,PetscViewer v) 17*4c02969dSBarry Smith { 18*4c02969dSBarry Smith PetscErrorCode ierr; 19*4c02969dSBarry Smith 20*4c02969dSBarry Smith PetscFunctionBegin; 21*4c02969dSBarry Smith ierr = PetscOptionsHead(PetscOptionsObject,"ADIOS PetscViewer Options");CHKERRQ(ierr); 22*4c02969dSBarry Smith ierr = PetscOptionsTail();CHKERRQ(ierr); 23*4c02969dSBarry Smith PetscFunctionReturn(0); 24*4c02969dSBarry Smith } 25*4c02969dSBarry Smith 26*4c02969dSBarry Smith static PetscErrorCode PetscViewerFileClose_ADIOS(PetscViewer viewer) 27*4c02969dSBarry Smith { 28*4c02969dSBarry Smith PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*)viewer->data; 29*4c02969dSBarry Smith PetscErrorCode ierr; 30*4c02969dSBarry Smith 31*4c02969dSBarry Smith PetscFunctionBegin; 32*4c02969dSBarry Smith ierr = PetscFree(adios->filename);CHKERRQ(ierr); 33*4c02969dSBarry Smith PetscFunctionReturn(0); 34*4c02969dSBarry Smith } 35*4c02969dSBarry Smith 36*4c02969dSBarry Smith PetscErrorCode PetscViewerDestroy_ADIOS(PetscViewer viewer) 37*4c02969dSBarry Smith { 38*4c02969dSBarry Smith PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data; 39*4c02969dSBarry Smith PetscErrorCode ierr; 40*4c02969dSBarry Smith 41*4c02969dSBarry Smith PetscFunctionBegin; 42*4c02969dSBarry Smith ierr = PetscViewerFileClose_ADIOS(viewer);CHKERRQ(ierr); 43*4c02969dSBarry Smith while (adios->groups) { 44*4c02969dSBarry Smith GroupList *tmp = adios->groups->next; 45*4c02969dSBarry Smith 46*4c02969dSBarry Smith ierr = PetscFree(adios->groups->name);CHKERRQ(ierr); 47*4c02969dSBarry Smith ierr = PetscFree(adios->groups);CHKERRQ(ierr); 48*4c02969dSBarry Smith adios->groups = tmp; 49*4c02969dSBarry Smith } 50*4c02969dSBarry Smith ierr = PetscFree(adios);CHKERRQ(ierr); 51*4c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",NULL);CHKERRQ(ierr); 52*4c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileGetName_C",NULL);CHKERRQ(ierr); 53*4c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",NULL);CHKERRQ(ierr); 54*4c02969dSBarry Smith PetscFunctionReturn(0); 55*4c02969dSBarry Smith } 56*4c02969dSBarry Smith 57*4c02969dSBarry Smith PetscErrorCode PetscViewerFileSetMode_ADIOS(PetscViewer viewer, PetscFileMode type) 58*4c02969dSBarry Smith { 59*4c02969dSBarry Smith PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data; 60*4c02969dSBarry Smith 61*4c02969dSBarry Smith PetscFunctionBegin; 62*4c02969dSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 63*4c02969dSBarry Smith adios->btype = type; 64*4c02969dSBarry Smith PetscFunctionReturn(0); 65*4c02969dSBarry Smith } 66*4c02969dSBarry Smith 67*4c02969dSBarry Smith PetscErrorCode PetscViewerFileSetName_ADIOS(PetscViewer viewer, const char name[]) 68*4c02969dSBarry Smith { 69*4c02969dSBarry Smith PetscFunctionBegin; 70*4c02969dSBarry Smith PetscFunctionReturn(0); 71*4c02969dSBarry Smith } 72*4c02969dSBarry Smith 73*4c02969dSBarry Smith static PetscErrorCode PetscViewerFileGetName_ADIOS(PetscViewer viewer,const char **name) 74*4c02969dSBarry Smith { 75*4c02969dSBarry Smith PetscViewer_ADIOS *vadios = (PetscViewer_ADIOS*)viewer->data; 76*4c02969dSBarry Smith 77*4c02969dSBarry Smith PetscFunctionBegin; 78*4c02969dSBarry Smith *name = vadios->filename; 79*4c02969dSBarry Smith PetscFunctionReturn(0); 80*4c02969dSBarry Smith } 81*4c02969dSBarry Smith 82*4c02969dSBarry Smith /*MC 83*4c02969dSBarry Smith PETSCVIEWERADIOS - A viewer that writes to an ADIOS file 84*4c02969dSBarry Smith 85*4c02969dSBarry Smith 86*4c02969dSBarry Smith .seealso: PetscViewerADIOSOpen(), PetscViewerStringSPrintf(), PetscViewerSocketOpen(), PetscViewerDrawOpen(), PETSCVIEWERSOCKET, 87*4c02969dSBarry Smith PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY, PETSCVIEWERDRAW, PETSCVIEWERSTRING, 88*4c02969dSBarry Smith PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB, 89*4c02969dSBarry Smith PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType() 90*4c02969dSBarry Smith 91*4c02969dSBarry Smith Level: beginner 92*4c02969dSBarry Smith M*/ 93*4c02969dSBarry Smith 94*4c02969dSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerCreate_ADIOS(PetscViewer v) 95*4c02969dSBarry Smith { 96*4c02969dSBarry Smith PetscViewer_ADIOS *adios; 97*4c02969dSBarry Smith PetscErrorCode ierr; 98*4c02969dSBarry Smith 99*4c02969dSBarry Smith PetscFunctionBegin; 100*4c02969dSBarry Smith ierr = PetscNewLog(v,&adios);CHKERRQ(ierr); 101*4c02969dSBarry Smith 102*4c02969dSBarry Smith v->data = (void*) adios; 103*4c02969dSBarry Smith v->ops->destroy = PetscViewerDestroy_ADIOS; 104*4c02969dSBarry Smith v->ops->setfromoptions = PetscViewerSetFromOptions_ADIOS; 105*4c02969dSBarry Smith v->ops->flush = 0; 106*4c02969dSBarry Smith adios->btype = (PetscFileMode) -1; 107*4c02969dSBarry Smith adios->filename = 0; 108*4c02969dSBarry Smith adios->timestep = -1; 109*4c02969dSBarry Smith adios->groups = NULL; 110*4c02969dSBarry Smith 111*4c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetName_C",PetscViewerFileSetName_ADIOS);CHKERRQ(ierr); 112*4c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileGetName_C",PetscViewerFileGetName_ADIOS);CHKERRQ(ierr); 113*4c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_ADIOS);CHKERRQ(ierr); 114*4c02969dSBarry Smith PetscFunctionReturn(0); 115*4c02969dSBarry Smith } 116*4c02969dSBarry Smith 117*4c02969dSBarry Smith /*@C 118*4c02969dSBarry Smith PetscViewerADIOSOpen - Opens a file for ADIOS input/output. 119*4c02969dSBarry Smith 120*4c02969dSBarry Smith Collective on MPI_Comm 121*4c02969dSBarry Smith 122*4c02969dSBarry Smith Input Parameters: 123*4c02969dSBarry Smith + comm - MPI communicator 124*4c02969dSBarry Smith . name - name of file 125*4c02969dSBarry Smith - type - type of file 126*4c02969dSBarry Smith $ FILE_MODE_WRITE - create new file for binary output 127*4c02969dSBarry Smith $ FILE_MODE_READ - open existing file for binary input 128*4c02969dSBarry Smith $ FILE_MODE_APPEND - open existing file for binary output 129*4c02969dSBarry Smith 130*4c02969dSBarry Smith Output Parameter: 131*4c02969dSBarry Smith . adiosv - PetscViewer for ADIOS input/output to use with the specified file 132*4c02969dSBarry Smith 133*4c02969dSBarry Smith Level: beginner 134*4c02969dSBarry Smith 135*4c02969dSBarry Smith Note: 136*4c02969dSBarry Smith This PetscViewer should be destroyed with PetscViewerDestroy(). 137*4c02969dSBarry Smith 138*4c02969dSBarry Smith Concepts: ADIOS files 139*4c02969dSBarry Smith Concepts: PetscViewerADIOS^creating 140*4c02969dSBarry Smith 141*4c02969dSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PetscViewerADIOSSetBaseDimension2(), 142*4c02969dSBarry Smith PetscViewerADIOSSetSPOutput(), PetscViewerADIOSGetBaseDimension2(), VecView(), MatView(), VecLoad(), 143*4c02969dSBarry Smith MatLoad(), PetscFileMode, PetscViewer 144*4c02969dSBarry Smith @*/ 145*4c02969dSBarry Smith PetscErrorCode PetscViewerADIOSOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *adiosv) 146*4c02969dSBarry Smith { 147*4c02969dSBarry Smith PetscErrorCode ierr; 148*4c02969dSBarry Smith 149*4c02969dSBarry Smith PetscFunctionBegin; 150*4c02969dSBarry Smith ierr = PetscViewerCreate(comm, adiosv);CHKERRQ(ierr); 151*4c02969dSBarry Smith ierr = PetscViewerSetType(*adiosv, PETSCVIEWERADIOS);CHKERRQ(ierr); 152*4c02969dSBarry Smith ierr = PetscViewerFileSetMode(*adiosv, type);CHKERRQ(ierr); 153*4c02969dSBarry Smith ierr = PetscViewerFileSetName(*adiosv, name);CHKERRQ(ierr); 154*4c02969dSBarry Smith PetscFunctionReturn(0); 155*4c02969dSBarry Smith } 156*4c02969dSBarry Smith 157*4c02969dSBarry Smith /*@C 158*4c02969dSBarry Smith PetscDataTypeToADIOSDataType - Converts the PETSc name of a datatype to its ADIOS name. 159*4c02969dSBarry Smith 160*4c02969dSBarry Smith Not collective 161*4c02969dSBarry Smith 162*4c02969dSBarry Smith Input Parameter: 163*4c02969dSBarry Smith . ptype - the PETSc datatype name (for example PETSC_DOUBLE) 164*4c02969dSBarry Smith 165*4c02969dSBarry Smith Output Parameter: 166*4c02969dSBarry Smith . mtype - the MPI datatype (for example MPI_DOUBLE, ...) 167*4c02969dSBarry Smith 168*4c02969dSBarry Smith Level: advanced 169*4c02969dSBarry Smith 170*4c02969dSBarry Smith Developer Notes: These have not been verified 171*4c02969dSBarry Smith 172*4c02969dSBarry Smith .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType() 173*4c02969dSBarry Smith @*/ 174*4c02969dSBarry Smith PetscErrorCode PetscDataTypeToADIOSDataType(PetscDataType ptype, enum ADIOS_DATATYPES *htype) 175*4c02969dSBarry Smith { 176*4c02969dSBarry Smith PetscFunctionBegin; 177*4c02969dSBarry Smith if (ptype == PETSC_INT) 178*4c02969dSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 179*4c02969dSBarry Smith *htype = adios_long; 180*4c02969dSBarry Smith #else 181*4c02969dSBarry Smith *htype = adios_integer; 182*4c02969dSBarry Smith #endif 183*4c02969dSBarry Smith else if (ptype == PETSC_ENUM) *htype = adios_integer; 184*4c02969dSBarry Smith else if (ptype == PETSC_DOUBLE) *htype = adios_double; 185*4c02969dSBarry Smith else if (ptype == PETSC_LONG) *htype = adios_long; 186*4c02969dSBarry Smith else if (ptype == PETSC_SHORT) *htype = adios_short; 187*4c02969dSBarry Smith else if (ptype == PETSC_FLOAT) *htype = adios_real; 188*4c02969dSBarry Smith else if (ptype == PETSC_CHAR) *htype = adios_string_array; 189*4c02969dSBarry Smith else if (ptype == PETSC_STRING) *htype = adios_string; 190*4c02969dSBarry Smith else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported PETSc datatype"); 191*4c02969dSBarry Smith PetscFunctionReturn(0); 192*4c02969dSBarry Smith } 193*4c02969dSBarry Smith 194*4c02969dSBarry Smith /*@C 195*4c02969dSBarry Smith PetscADIOSDataTypeToPetscDataType - Finds the PETSc name of a datatype from its ADIOS name 196*4c02969dSBarry Smith 197*4c02969dSBarry Smith Not collective 198*4c02969dSBarry Smith 199*4c02969dSBarry Smith Input Parameter: 200*4c02969dSBarry Smith . htype - the ADIOS datatype (for example H5T_NATIVE_DOUBLE, ...) 201*4c02969dSBarry Smith 202*4c02969dSBarry Smith Output Parameter: 203*4c02969dSBarry Smith . ptype - the PETSc datatype name (for example PETSC_DOUBLE) 204*4c02969dSBarry Smith 205*4c02969dSBarry Smith Level: advanced 206*4c02969dSBarry Smith 207*4c02969dSBarry Smith Developer Notes: These have not been verified 208*4c02969dSBarry Smith 209*4c02969dSBarry Smith .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType() 210*4c02969dSBarry Smith @*/ 211*4c02969dSBarry Smith PetscErrorCode PetscADIOSDataTypeToPetscDataType(enum ADIOS_DATATYPES htype, PetscDataType *ptype) 212*4c02969dSBarry Smith { 213*4c02969dSBarry Smith PetscFunctionBegin; 214*4c02969dSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 215*4c02969dSBarry Smith if (htype == adios_integer) *ptype = PETSC_ENUM; 216*4c02969dSBarry Smith else if (htype == adios_long) *ptype = PETSC_INT; 217*4c02969dSBarry Smith #else 218*4c02969dSBarry Smith if (htype == adios_integer) *ptype = PETSC_INT; 219*4c02969dSBarry Smith #endif 220*4c02969dSBarry Smith else if (htype == adios_double) *ptype = PETSC_DOUBLE; 221*4c02969dSBarry Smith else if (htype == adios_long) *ptype = PETSC_LONG; 222*4c02969dSBarry Smith else if (htype == adios_short) *ptype = PETSC_SHORT; 223*4c02969dSBarry Smith else if (htype == adios_real) *ptype = PETSC_FLOAT; 224*4c02969dSBarry Smith else if (htype == adios_string_array) *ptype = PETSC_CHAR; 225*4c02969dSBarry Smith else if (htype == adios_string) *ptype = PETSC_STRING; 226*4c02969dSBarry Smith else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported ADIOS datatype"); 227*4c02969dSBarry Smith PetscFunctionReturn(0); 228*4c02969dSBarry Smith } 229