Actual source code: adios2.c

  1: #include <petsc/private/viewerimpl.h>
  2: #include <adios2_c.h>
  3: #include <petsc/private/vieweradios2impl.h>

  5: static PetscErrorCode PetscViewerSetFromOptions_ADIOS2(PetscOptionItems *PetscOptionsObject,PetscViewer v)
  6: {

 10:   PetscOptionsHead(PetscOptionsObject,"ADIOS2 PetscViewer Options");
 11:   PetscOptionsTail();
 12:   return(0);
 13: }

 15: static PetscErrorCode PetscViewerFileClose_ADIOS2(PetscViewer viewer)
 16: {
 17:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*)viewer->data;
 18:   PetscErrorCode     ierr;

 21:   switch (adios2->btype) {
 22:   case FILE_MODE_READ:
 23:     /* adios2_read_close(adios2->adios2_fp); */
 24:     break;
 25:   case FILE_MODE_WRITE:
 26:     /* adios2_close(adios2->adios2_handle); */
 27:     break;
 28:   default:
 29:     break;
 30:   }
 31:   PetscFree(adios2->filename);
 32:   return(0);
 33: }

 35: PetscErrorCode PetscViewerDestroy_ADIOS2(PetscViewer viewer)
 36: {
 37:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;
 38:   PetscErrorCode     ierr;

 41:   PetscViewerFileClose_ADIOS2(viewer);
 42:   PetscFree(adios2);
 43:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",NULL);
 44:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileGetName_C",NULL);
 45:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",NULL);
 46:   return(0);
 47: }

 49: PetscErrorCode  PetscViewerFileSetMode_ADIOS2(PetscViewer viewer, PetscFileMode type)
 50: {
 51:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;

 54:   adios2->btype = type;
 55:   return(0);
 56: }

 58: PetscErrorCode  PetscViewerFileSetName_ADIOS2(PetscViewer viewer, const char name[])
 59: {
 60:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;
 61:   PetscErrorCode     ierr;

 64:   PetscFree(adios2->filename);
 65:   PetscStrallocpy(name, &adios2->filename);
 66:   /* Create or open the file collectively */
 67:   switch (adios2->btype) {
 68:   case FILE_MODE_READ:
 69:     /* adios2->adios2_fp = adios2_read_open_file(adios2->filename,ADIOS2_READ_METHOD_BP,PetscObjectComm((PetscObject)viewer)); */
 70:     break;
 71:   case FILE_MODE_WRITE:
 72:     /* adios2_open(&adios2->adios2_handle,"PETSc",adios2->filename,"w",PetscObjectComm((PetscObject)viewer)); */
 73:     break;
 74:   case FILE_MODE_UNDEFINED:
 75:     SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ORDER,"Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
 76:   default:
 77:     SETERRQ1(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Unsupported file mode %s",PetscFileModes[adios2->btype]);
 78:   }
 79:   return(0);
 80: }

 82: static PetscErrorCode PetscViewerFileGetName_ADIOS2(PetscViewer viewer,const char **name)
 83: {
 84:   PetscViewer_ADIOS2 *vadios2 = (PetscViewer_ADIOS2*)viewer->data;

 87:   *name = vadios2->filename;
 88:   return(0);
 89: }

 91: /*MC
 92:    PETSCVIEWERADIOS2 - A viewer that writes to an ADIOS2 file


 95: .seealso:  PetscViewerADIOS2Open(), PetscViewerStringSPrintf(), PetscViewerSocketOpen(), PetscViewerDrawOpen(), PETSCVIEWERSOCKET,
 96:            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY, PETSCVIEWERDRAW, PETSCVIEWERSTRING,
 97:            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
 98:            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()

100:   Level: beginner
101: M*/

103: PETSC_EXTERN PetscErrorCode PetscViewerCreate_ADIOS2(PetscViewer v)
104: {
105:   PetscViewer_ADIOS2 *adios2;
106:   PetscErrorCode     ierr;

109:   PetscNewLog(v,&adios2);

111:   v->data                = (void*) adios2;
112:   v->ops->destroy        = PetscViewerDestroy_ADIOS2;
113:   v->ops->setfromoptions = PetscViewerSetFromOptions_ADIOS2;
114:   v->ops->flush          = NULL;
115:   adios2->btype          = FILE_MODE_UNDEFINED;
116:   adios2->filename       = NULL;
117:   adios2->timestep       = -1;

119:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetName_C",PetscViewerFileSetName_ADIOS2);
120:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileGetName_C",PetscViewerFileGetName_ADIOS2);
121:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_ADIOS2);
122:   return(0);
123: }

125: /*@C
126:    PetscViewerADIOS2Open - Opens a file for ADIOS2 input/output.

128:    Collective

130:    Input Parameters:
131: +  comm - MPI communicator
132: .  name - name of file
133: -  type - type of file
134: $    FILE_MODE_WRITE - create new file for binary output
135: $    FILE_MODE_READ - open existing file for binary input
136: $    FILE_MODE_APPEND - open existing file for binary output

138:    Output Parameter:
139: .  adios2v - PetscViewer for ADIOS2 input/output to use with the specified file

141:    Level: beginner

143:    Note:
144:    This PetscViewer should be destroyed with PetscViewerDestroy().


147: .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PetscViewerHDF5Open(),
148:           VecView(), MatView(), VecLoad(), PetscViewerSetType(), PetscViewerFileSetMode(), PetscViewerFileSetName()
149:           MatLoad(), PetscFileMode, PetscViewer
150: @*/
151: PetscErrorCode  PetscViewerADIOS2Open(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *adios2v)
152: {

156:   PetscViewerCreate(comm, adios2v);
157:   PetscViewerSetType(*adios2v, PETSCVIEWERADIOS2);
158:   PetscViewerFileSetMode(*adios2v, type);
159:   PetscViewerFileSetName(*adios2v, name);
160:   return(0);
161: }