Actual source code: adios.c

petsc-3.10.5 2019-03-28
Report Typos and Errors
  1:  #include <petsc/private/viewerimpl.h>
  2: #include <adios.h>
  3: #include <adios_read.h>

  5:  #include <petsc/private/vieweradiosimpl.h>

  7: static PetscErrorCode PetscViewerSetFromOptions_ADIOS(PetscOptionItems *PetscOptionsObject,PetscViewer v)
  8: {

 12:   PetscOptionsHead(PetscOptionsObject,"ADIOS PetscViewer Options");
 13:   PetscOptionsTail();
 14:   return(0);
 15: }

 17: static PetscErrorCode PetscViewerFileClose_ADIOS(PetscViewer viewer)
 18: {
 19:   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*)viewer->data;
 20:   PetscErrorCode    ierr;

 23:   switch (adios->btype) {
 24:   case FILE_MODE_READ:
 25:     adios_read_close(adios->adios_fp);
 26:     break;
 27:   case FILE_MODE_APPEND:
 28:     break;
 29:   case FILE_MODE_WRITE:
 30:      adios_close(adios->adios_handle);
 31:     break;
 32:   default:
 33:     break;
 34:   }
 35:   PetscFree(adios->filename);
 36:   return(0);
 37: }

 39: PetscErrorCode PetscViewerDestroy_ADIOS(PetscViewer viewer)
 40: {
 41:   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data;
 42:   PetscErrorCode    ierr;

 45:   PetscViewerFileClose_ADIOS(viewer);
 46:   PetscFree(adios);
 47:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",NULL);
 48:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileGetName_C",NULL);
 49:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",NULL);
 50:   return(0);
 51: }

 53: PetscErrorCode  PetscViewerFileSetMode_ADIOS(PetscViewer viewer, PetscFileMode type)
 54: {
 55:   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data;

 59:   adios->btype = type;
 60:   return(0);
 61: }

 63: PetscErrorCode  PetscViewerFileSetName_ADIOS(PetscViewer viewer, const char name[])
 64: {
 65:   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data;
 66:   PetscErrorCode    ierr;

 69:   if (adios->filename) {PetscFree(adios->filename);}
 70:   PetscStrallocpy(name, &adios->filename);
 71:   /* Create or open the file collectively */
 72:   switch (adios->btype) {
 73:   case FILE_MODE_READ:
 74:     adios->adios_fp = adios_read_open_file(adios->filename,ADIOS_READ_METHOD_BP,PetscObjectComm((PetscObject)viewer));
 75:     break;
 76:   case FILE_MODE_APPEND:
 77:     break;
 78:   case FILE_MODE_WRITE:
 79:     adios_open(&adios->adios_handle,"PETSc",adios->filename,"w",PetscObjectComm((PetscObject)viewer));
 80:     break;
 81:   default:
 82:     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER, "Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
 83:   }
 84:   return(0);
 85: }

 87: static PetscErrorCode PetscViewerFileGetName_ADIOS(PetscViewer viewer,const char **name)
 88: {
 89:   PetscViewer_ADIOS *vadios = (PetscViewer_ADIOS*)viewer->data;

 92:   *name = vadios->filename;
 93:   return(0);
 94: }

 96: /*MC
 97:    PETSCVIEWERADIOS - A viewer that writes to an ADIOS file


100: .seealso:  PetscViewerADIOSOpen(), PetscViewerStringSPrintf(), PetscViewerSocketOpen(), PetscViewerDrawOpen(), PETSCVIEWERSOCKET,
101:            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY, PETSCVIEWERDRAW, PETSCVIEWERSTRING,
102:            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
103:            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()

105:   Level: beginner
106: M*/

108: PETSC_EXTERN PetscErrorCode PetscViewerCreate_ADIOS(PetscViewer v)
109: {
110:   PetscViewer_ADIOS *adios;
111:   PetscErrorCode    ierr;

114:   PetscNewLog(v,&adios);

116:   v->data                = (void*) adios;
117:   v->ops->destroy        = PetscViewerDestroy_ADIOS;
118:   v->ops->setfromoptions = PetscViewerSetFromOptions_ADIOS;
119:   v->ops->flush          = 0;
120:   adios->btype            = (PetscFileMode) -1;
121:   adios->filename         = 0;
122:   adios->timestep         = -1;

124:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetName_C",PetscViewerFileSetName_ADIOS);
125:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileGetName_C",PetscViewerFileGetName_ADIOS);
126:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_ADIOS);
127:   return(0);
128: }

130: /*@C
131:    PetscViewerADIOSOpen - Opens a file for ADIOS input/output.

133:    Collective on MPI_Comm

135:    Input Parameters:
136: +  comm - MPI communicator
137: .  name - name of file
138: -  type - type of file
139: $    FILE_MODE_WRITE - create new file for binary output
140: $    FILE_MODE_READ - open existing file for binary input
141: $    FILE_MODE_APPEND - open existing file for binary output

143:    Output Parameter:
144: .  adiosv - PetscViewer for ADIOS input/output to use with the specified file

146:    Level: beginner

148:    Note:
149:    This PetscViewer should be destroyed with PetscViewerDestroy().

151:    Concepts: ADIOS files
152:    Concepts: PetscViewerADIOS^creating

154: .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PetscViewerHDF5Open(),
155:           VecView(), MatView(), VecLoad(), PetscViewerSetType(), PetscViewerFileSetMode(), PetscViewerFileSetName()
156:           MatLoad(), PetscFileMode, PetscViewer
157: @*/
158: PetscErrorCode  PetscViewerADIOSOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *adiosv)
159: {

163:   PetscViewerCreate(comm, adiosv);
164:   PetscViewerSetType(*adiosv, PETSCVIEWERADIOS);
165:   PetscViewerFileSetMode(*adiosv, type);
166:   PetscViewerFileSetName(*adiosv, name);
167:   return(0);
168: }

170: /*@C
171:   PetscDataTypeToADIOSDataType - Converts the PETSc name of a datatype to its ADIOS name.

173:   Not collective

175:   Input Parameter:
176: . ptype - the PETSc datatype name (for example PETSC_DOUBLE)

178:   Output Parameter:
179: . mtype - the MPI datatype (for example MPI_DOUBLE, ...)

181:   Level: advanced

183:   Developer Notes: These have not been verified

185: .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType()
186: @*/
187: PetscErrorCode PetscDataTypeToADIOSDataType(PetscDataType ptype, enum ADIOS_DATATYPES *htype)
188: {
190:   if (ptype == PETSC_INT)
191: #if defined(PETSC_USE_64BIT_INDICES)
192:                                        *htype = adios_long;
193: #else
194:                                        *htype = adios_integer;
195: #endif
196:   else if (ptype == PETSC_ENUM)        *htype = adios_integer;
197:   else if (ptype == PETSC_DOUBLE)      *htype = adios_double;
198:   else if (ptype == PETSC_LONG)        *htype = adios_long;
199:   else if (ptype == PETSC_SHORT)       *htype = adios_short;
200:   else if (ptype == PETSC_FLOAT)       *htype = adios_real;
201:   else if (ptype == PETSC_CHAR)        *htype = adios_string_array;
202:   else if (ptype == PETSC_STRING)      *htype = adios_string;
203:   else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported PETSc datatype");
204:   return(0);
205: }

207: /*@C
208:   PetscADIOSDataTypeToPetscDataType - Finds the PETSc name of a datatype from its ADIOS name

210:   Not collective

212:   Input Parameter:
213: . htype - the ADIOS datatype (for example H5T_NATIVE_DOUBLE, ...)

215:   Output Parameter:
216: . ptype - the PETSc datatype name (for example PETSC_DOUBLE)

218:   Level: advanced

220:   Developer Notes: These have not been verified

222: .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType()
223: @*/
224: PetscErrorCode PetscADIOSDataTypeToPetscDataType(enum ADIOS_DATATYPES htype, PetscDataType *ptype)
225: {
227: #if defined(PETSC_USE_64BIT_INDICES)
228:   if      (htype == adios_integer)     *ptype = PETSC_ENUM;
229:   else if (htype == adios_long)        *ptype = PETSC_INT;
230: #else
231:   if      (htype == adios_integer)     *ptype = PETSC_INT;
232: #endif
233:   else if (htype == adios_double)      *ptype = PETSC_DOUBLE;
234:   else if (htype == adios_long)        *ptype = PETSC_LONG;
235:   else if (htype == adios_short)       *ptype = PETSC_SHORT;
236:   else if (htype == adios_real)        *ptype = PETSC_FLOAT;
237:   else if (htype == adios_string_array) *ptype = PETSC_CHAR;
238:   else if (htype == adios_string)       *ptype = PETSC_STRING;
239:   else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported ADIOS datatype");
240:   return(0);
241: }