Start MPI-IO VTK Writer

This commit is contained in:
Jan Eitzinger 2023-02-05 11:22:05 +01:00
parent 730c587158
commit 394e4643ec
2 changed files with 31 additions and 36 deletions

View File

@ -6,8 +6,10 @@
*/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "mpi.h"
#include "vtkWriter.h" #include "vtkWriter.h"
#define G(v, i, j, k) v[(k)*imax * jmax + (j)*imax + (i)] #define G(v, i, j, k) v[(k)*imax * jmax + (j)*imax + (i)]
@ -28,39 +30,45 @@ static float floatSwap(float f)
static void writeHeader(VtkOptions* o) static void writeHeader(VtkOptions* o)
{ {
fprintf(o->fh, "# vtk DataFile Version 3.0\n"); const size_t MAX_HEADER = 200;
fprintf(o->fh, "PAMPI cfd solver output\n");
if (o->fmt == ASCII) {
fprintf(o->fh, "ASCII\n");
} else if (o->fmt == BINARY) {
fprintf(o->fh, "BINARY\n");
}
fprintf(o->fh, "DATASET STRUCTURED_POINTS\n"); char* header = (char*)malloc(MAX_HEADER);
fprintf(o->fh, "DIMENSIONS %d %d %d\n", o->grid.imax, o->grid.jmax, o->grid.kmax); char* cursor = header;
fprintf(o->fh,
cursor += sprintf(cursor, "# vtk DataFile Version 3.0\n");
cursor += sprintf(cursor, "PAMPI cfd solver output\n");
cursor += sprintf(cursor, "BINARY\n");
cursor += sprintf(cursor, "DATASET STRUCTURED_POINTS\n");
cursor += sprintf(cursor,
"DIMENSIONS %d %d %d\n",
o->grid.imax,
o->grid.jmax,
o->grid.kmax);
cursor += sprintf(cursor,
"ORIGIN %f %f %f\n", "ORIGIN %f %f %f\n",
o->grid.dx * 0.5, o->grid.dx * 0.5,
o->grid.dy * 0.5, o->grid.dy * 0.5,
o->grid.dz * 0.5); o->grid.dz * 0.5);
fprintf(o->fh, "SPACING %f %f %f\n", o->grid.dx, o->grid.dy, o->grid.dz); cursor += sprintf(cursor, "SPACING %f %f %f\n", o->grid.dx, o->grid.dy, o->grid.dz);
fprintf(o->fh, "POINT_DATA %d\n", o->grid.imax * o->grid.jmax * o->grid.kmax); cursor += sprintf(cursor,
"POINT_DATA %d\n",
o->grid.imax * o->grid.jmax * o->grid.kmax);
} }
void vtkOpen(VtkOptions* o, char* problem) void vtkOpen(VtkOptions* o, char* problem)
{ {
char filename[50]; char filename[50];
if (o->mode == UNIX) { snprintf(filename, 50, "%s-p%d.vtk", problem, o->comm.size);
if (commIsMaster(&o->comm)) { MPI_File_open(o->comm.comm,
snprintf(filename, 50, "%s-p%d.vtk", problem, o->comm.size); filename,
o->fh = fopen(filename, "w"); MPI_MODE_WRONLY | MPI_MODE_CREATE,
writeHeader(o); MPI_INFO_NULL,
} &o->fh);
} else if (o->mode == MPI) {
}
if (commIsMaster(&o->comm)) printf("Writing VTK output for %s\n", problem); if (commIsMaster(&o->comm)) printf("Writing VTK output for %s\n", problem);
writeHeader(o);
} }
static void writeScalar(VtkOptions* o, double* s) static void writeScalar(VtkOptions* o, double* s)
@ -153,13 +161,4 @@ void vtkVector(VtkOptions* o, char* name, VtkVector vec)
} }
} }
void vtkClose(VtkOptions* o) void vtkClose(VtkOptions* o) { MPI_File_close(o->fh); }
{
if (o->mode == UNIX) {
if (commIsMaster(&o->comm)) {
fclose(o->fh);
o->fh = NULL;
}
} else if (o->mode == MPI) {
}
}

View File

@ -6,19 +6,15 @@
*/ */
#ifndef __VTKWRITER_H_ #ifndef __VTKWRITER_H_
#define __VTKWRITER_H_ #define __VTKWRITER_H_
#include <mpi.h>
#include <stdio.h> #include <stdio.h>
#include "comm.h" #include "comm.h"
#include "grid.h" #include "grid.h"
typedef enum VtkFormat { ASCII = 0, BINARY } VtkFormat;
typedef enum VtkMode { UNIX = 0, MPI } VtkMode;
typedef struct VtkOptions { typedef struct VtkOptions {
VtkFormat fmt;
VtkMode mode;
Grid grid; Grid grid;
FILE* fh; MPI_File fh;
Comm comm; Comm comm;
} VtkOptions; } VtkOptions;