Actual source code: adios.c
petsc-3.13.6 2020-09-29
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
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().
152: .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PetscViewerHDF5Open(),
153: VecView(), MatView(), VecLoad(), PetscViewerSetType(), PetscViewerFileSetMode(), PetscViewerFileSetName()
154: MatLoad(), PetscFileMode, PetscViewer
155: @*/
156: PetscErrorCode PetscViewerADIOSOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *adiosv)
157: {
161: PetscViewerCreate(comm, adiosv);
162: PetscViewerSetType(*adiosv, PETSCVIEWERADIOS);
163: PetscViewerFileSetMode(*adiosv, type);
164: PetscViewerFileSetName(*adiosv, name);
165: return(0);
166: }
168: /*@C
169: PetscDataTypeToADIOSDataType - Converts the PETSc name of a datatype to its ADIOS name.
171: Not collective
173: Input Parameter:
174: . ptype - the PETSc datatype name (for example PETSC_DOUBLE)
176: Output Parameter:
177: . mtype - the MPI datatype (for example MPI_DOUBLE, ...)
179: Level: advanced
181: Developer Notes: These have not been verified
183: .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType()
184: @*/
185: PetscErrorCode PetscDataTypeToADIOSDataType(PetscDataType ptype, enum ADIOS_DATATYPES *htype)
186: {
188: if (ptype == PETSC_INT)
189: #if defined(PETSC_USE_64BIT_INDICES)
190: *htype = adios_long;
191: #else
192: *htype = adios_integer;
193: #endif
194: else if (ptype == PETSC_ENUM) *htype = adios_integer;
195: else if (ptype == PETSC_DOUBLE) *htype = adios_double;
196: else if (ptype == PETSC_LONG) *htype = adios_long;
197: else if (ptype == PETSC_SHORT) *htype = adios_short;
198: else if (ptype == PETSC_FLOAT) *htype = adios_real;
199: else if (ptype == PETSC_CHAR) *htype = adios_string_array;
200: else if (ptype == PETSC_STRING) *htype = adios_string;
201: else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported PETSc datatype");
202: return(0);
203: }
205: /*@C
206: PetscADIOSDataTypeToPetscDataType - Finds the PETSc name of a datatype from its ADIOS name
208: Not collective
210: Input Parameter:
211: . htype - the ADIOS datatype (for example H5T_NATIVE_DOUBLE, ...)
213: Output Parameter:
214: . ptype - the PETSc datatype name (for example PETSC_DOUBLE)
216: Level: advanced
218: Developer Notes: These have not been verified
220: .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType()
221: @*/
222: PetscErrorCode PetscADIOSDataTypeToPetscDataType(enum ADIOS_DATATYPES htype, PetscDataType *ptype)
223: {
225: #if defined(PETSC_USE_64BIT_INDICES)
226: if (htype == adios_integer) *ptype = PETSC_ENUM;
227: else if (htype == adios_long) *ptype = PETSC_INT;
228: #else
229: if (htype == adios_integer) *ptype = PETSC_INT;
230: #endif
231: else if (htype == adios_double) *ptype = PETSC_DOUBLE;
232: else if (htype == adios_long) *ptype = PETSC_LONG;
233: else if (htype == adios_short) *ptype = PETSC_SHORT;
234: else if (htype == adios_real) *ptype = PETSC_FLOAT;
235: else if (htype == adios_string_array) *ptype = PETSC_CHAR;
236: else if (htype == adios_string) *ptype = PETSC_STRING;
237: else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported ADIOS datatype");
238: return(0);
239: }