Commit 72dcf141 authored by brugger's avatar brugger

I enhanced the xdmf_writer library to handle outputting unstructured

grids in parallel. I also added an example of writing an unstructured 
grid in parallel.



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@19913 18c085ea-50e0-402c-830e-de6fd14e8384
parent ed7ca87a
......@@ -73,6 +73,9 @@ IF(VISIT_PARALLEL)
ADD_PARALLEL_EXECUTABLE(xdmf_mpi_example2 xdmf_mpi_example2.c)
TARGET_LINK_LIBRARIES(xdmf_mpi_example2 xdmf_writer_par)
ADD_PARALLEL_EXECUTABLE(xdmf_mpi_example3 xdmf_mpi_example3.c)
TARGET_LINK_LIBRARIES(xdmf_mpi_example3 xdmf_writer_par)
ADD_PARALLEL_LIBRARY(xdmf_writer_par xdmf_writer.c)
TARGET_LINK_LIBRARIES(xdmf_writer_par ${HDF5_LIB} ${ZLIB_LIB})
ENDIF(VISIT_PARALLEL)
......@@ -6,4 +6,6 @@ mxterm 1 12 240 -q pbatch -A bdivp
# To run the examples do the following.
srun -n 4 xdmf_mpi_example 2 50 50 10 2 2 1
srun -n 4 xdmf_mpi_example 2 50 50 10 2 2 1
srun -n 4 xdmf_mpi_example2 2 50 50 10 2 2 1
srun -n 4 xdmf_mpi_example3 2 50 50 10 2 2 1
......@@ -211,7 +211,7 @@ int main(int argc, char *argv[])
//
HDFFile *hdfFile = HdfParallelCreate("multi_curv3d", nFiles);
HdfPutCurvMultiMesh(hdfFile, "grid", XDMF_FLOAT, coords, 3, gridDims,
HdfPutCurvMultiMesh(hdfFile, XDMF_FLOAT, coords, 3, gridDims,
iBlocks, nBlocks);
HdfPutCurvMultiVar(hdfFile, 3, varNames, varTypes, varCentering,
......
......@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
//
HDFFile *hdfFile = HdfParallelCreate("multi_curv3d_grid", nFiles);
HdfPutCurvMultiMesh(hdfFile, "grid", XDMF_FLOAT, coords, 3, gridDims,
HdfPutCurvMultiMesh(hdfFile, XDMF_FLOAT, coords, 3, gridDims,
iBlocks, nBlocks);
HdfParallelClose(hdfFile);
......
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include <xdmf_writer.h>
int main(int argc, char *argv[])
{
int nProcs, iProc;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
MPI_Comm_rank(MPI_COMM_WORLD, &iProc);
if (iProc == 0)
fprintf(stderr, "nProcs=%d\n", nProcs);
//
// Parse the argument list.
//
if (argc != 8)
{
if (iProc == 0)
fprintf(stderr, "Usage: %s nFiles nX nY nZ nXDom nYDom nZDom\n",
argv[0]);
MPI_Finalize();
exit(-1);
}
int nFiles;
int nBlocks[3];
int nodeDims[3];
int zoneDims[3];
sscanf(argv[1], "%d", &nFiles);
sscanf(argv[2], "%d", &zoneDims[0]);
sscanf(argv[3], "%d", &zoneDims[1]);
sscanf(argv[4], "%d", &zoneDims[2]);
sscanf(argv[5], "%d", &nBlocks[0]);
sscanf(argv[6], "%d", &nBlocks[1]);
sscanf(argv[7], "%d", &nBlocks[2]);
nodeDims[0] = zoneDims[0] + 1;
nodeDims[1] = zoneDims[1] + 1;
nodeDims[2] = zoneDims[2] + 1;
if (iProc == 0)
{
fprintf(stderr, "nFiles=%d\n", nFiles);
fprintf(stderr, "nodeDims=%d,%d,%d\n",
nodeDims[0], nodeDims[1], nodeDims[2]);
fprintf(stderr, "zoneDims=%d,%d,%d\n",
zoneDims[0], zoneDims[1], zoneDims[2]);
fprintf(stderr, "nBlocks=%d,%d,%d\n",
nBlocks[0], nBlocks[1], nBlocks[2]);
}
if (nProcs != nBlocks[0] * nBlocks[1] * nBlocks[2])
{
if (iProc == 0)
fprintf(stderr, "The number of blocks per processor must be one.\n");
MPI_Finalize();
exit(-1);
}
if (nFiles < 1)
{
if (iProc == 0)
fprintf(stderr, "Invalid number of files.\n");
MPI_Finalize();
exit(-1);
}
//
// Calculate some values about the assignment of data to processors
// and the grid dimensions.
//
int id = iProc;
int iX = id / (nBlocks[1] * nBlocks[2]);
id %= (nBlocks[1] * nBlocks[2]);
int iY = id / nBlocks[2];
int iZ = id % nBlocks[2];
int nzones = zoneDims[0] * zoneDims[1] * zoneDims[2];
int nnodes = nodeDims[0] * nodeDims[1] * nodeDims[2];
//
// Create the raw data.
//
float *coords = (float *) malloc(nnodes * 3 * sizeof(float));
int *connectivity = (int *) malloc(nzones * 8 * sizeof(int));
float **vars = (float **) malloc(3 * sizeof(float*));
vars[0] = (float *) malloc(nzones * sizeof(float));
vars[1] = (float *) malloc(nnodes * sizeof(float));
vars[2] = (float *) malloc(nnodes * 3 * sizeof(float));
int ndx = 0;
int k;
for (k = 0; k < nodeDims[2]; k++)
{
int j;
for (j = 0; j < nodeDims[1]; j++)
{
int i;
for (i = 0; i < nodeDims[0]; i++)
{
coords[ndx++] = (float) (i + iX * zoneDims[0]);
coords[ndx++] = (float) (j + iY * zoneDims[1]);
coords[ndx++] = (float) (k + iZ * zoneDims[2]);
}
}
}
int nx = nodeDims[0];
int ny = nodeDims[1];
ndx = 0;
for (k = 0; k < zoneDims[2]; k++)
{
int j;
for (j = 0; j < zoneDims[1]; j++)
{
int i;
for (i = 0; i < zoneDims[0]; i++)
{
connectivity[ndx++] = (k + 0)*nx*ny + (j + 0)*nx + (i + 0);
connectivity[ndx++] = (k + 0)*nx*ny + (j + 0)*nx + (i + 1);
connectivity[ndx++] = (k + 0)*nx*ny + (j + 1)*nx + (i + 1);
connectivity[ndx++] = (k + 0)*nx*ny + (j + 1)*nx + (i + 0);
connectivity[ndx++] = (k + 1)*nx*ny + (j + 0)*nx + (i + 0);
connectivity[ndx++] = (k + 1)*nx*ny + (j + 0)*nx + (i + 1);
connectivity[ndx++] = (k + 1)*nx*ny + (j + 1)*nx + (i + 1);
connectivity[ndx++] = (k + 1)*nx*ny + (j + 1)*nx + (i + 0);
}
}
}
ndx = 0;
float *var = vars[0];
for (k = 0; k < zoneDims[2]; k++)
{
int j;
for (j = 0; j < zoneDims[1]; j++)
{
int i;
for (i = 0; i < zoneDims[0]; i++)
{
var[ndx++] = (float) (j + iY * zoneDims[1]) + 0.5;
}
}
}
ndx = 0;
var = vars[1];
for (k = 0; k < nodeDims[2]; k++)
{
int j;
for (j = 0; j < nodeDims[1]; j++)
{
int i;
for (i = 0; i < nodeDims[0]; i++)
{
double x = (double) (i + iX * zoneDims[0]);
double y = (double) (j + iY * zoneDims[1]);
double z = (double) (k + iZ * zoneDims[2]);
var[ndx++] = (float) sqrt(x*x + y*y + z*z);
}
}
}
ndx = 0;
var = vars[2];
for (k = 0; k < nodeDims[2]; k++)
{
int j;
for (j = 0; j < nodeDims[1]; j++)
{
int i;
for (i = 0; i < nodeDims[0]; i++)
{
var[ndx++] = (float) (i + iX * zoneDims[0]);
var[ndx++] = 0.;
var[ndx++] = 0.;
}
}
}
//
// Create the meta data.
//
char **varNames = (char **) malloc(sizeof(char*)*3);
varNames[0] = (char *) malloc(strlen("height")+1);
strcpy(varNames[0], "height");
varNames[1] = (char *) malloc(strlen("radius")+1);
strcpy(varNames[1], "radius");
varNames[2] = (char *) malloc(strlen("velocity")+1);
strcpy(varNames[2], "velocity");
int *varTypes = (int *) malloc(sizeof(int)*3);
varTypes[0] = XDMF_SCALAR;
varTypes[1] = XDMF_SCALAR;
varTypes[2] = XDMF_VECTOR;
int *varDataTypes = (int *) malloc(sizeof(int)*3);
varDataTypes[0] = XDMF_FLOAT;
varDataTypes[1] = XDMF_FLOAT;
varDataTypes[2] = XDMF_FLOAT;
int *varCentering = (int *) malloc(sizeof(int)*3);
varCentering[0] = XDMF_CELL_CENTER;
varCentering[1] = XDMF_NODE_CENTER;
varCentering[2] = XDMF_NODE_CENTER;
int gridDims[3];
gridDims[0] = zoneDims[0];
gridDims[1] = zoneDims[1];
gridDims[2] = zoneDims[2];
//
// Write the meta data to the XML file.
//
XDMFFile *xdmfFile = XdmfParallelCreate("multi_ucd3d", nFiles, 1.5);
XdmfPutUcdMultiVar(xdmfFile, "multi_ucd3d", "grid", XDMF_FLOAT,
nnodes, 3, XDMF_HEX, nzones, nzones*8, 3, varNames, varTypes,
varCentering, varDataTypes, iProc, nProcs);
XdmfParallelClose(xdmfFile);
//
// Write the raw data to the HDF5 file.
//
HDFFile *hdfFile = HdfParallelCreate("multi_ucd3d", nFiles);
HdfPutUcdMultiMesh(hdfFile, XDMF_FLOAT, coords, nnodes,
connectivity, nzones*8, iProc, nProcs);
HdfPutUcdMultiVar(hdfFile, 3, varNames, varTypes, varCentering,
varDataTypes, vars, 3, nnodes, nzones, iProc, nProcs);
HdfParallelClose(hdfFile);
//
// Free the raw data and meta data.
//
free(coords);
free(connectivity);
free(vars[0]);
free(vars[1]);
free(vars[2]);
free(vars);
free(varNames[0]);
free(varNames[1]);
free(varNames[2]);
free(varNames);
free(varTypes);
free(varDataTypes);
free(varCentering);
MPI_Finalize();
}
This diff is collapsed.
......@@ -80,15 +80,26 @@ void XDMF_WRITER_API XdmfPutCurvMultiVar(XDMFFile *xdmfFile,
const char *gridFileName, const char *gridName, int gridDataType,
int nVars, char **varNames, int *varTypes, int *varCentering,
int *varDataTypes, int nDims, int *dims, int *iBlock, int *nBlocks);
void XDMF_WRITER_API XdmfPutUcdMultiVar(XDMFFile *xdmfFile,
const char *gridFileName, const char *gridName, int coordDataType,
int nCoords, int coordDims, int cellType, int nCells,
int connectivityLength, int nVars, char **varNames, int *varTypes,
int *varCentering, int *varDataTypes, int iBlock, int nBlocks);
void XDMF_WRITER_API XdmfParallelClose(XDMFFile *xdmfFile);
HDFFile XDMF_WRITER_API *HdfParallelCreate(const char *fileName, int nFiles);
void XDMF_WRITER_API HdfPutCurvMultiMesh(HDFFile *hdfFile,
const char *gridName, int gridDataType, float *gridCoords,
int nDims, int *dims, int *iBlock, int *nBlocks);
int coordDataType, float *coords, int nDims, int *dims,
int *iBlock, int *nBlocks);
void XDMF_WRITER_API HdfPutCurvMultiVar(HDFFile *hdfFile, int nVars,
char **varNames, int *varTypes, int *varCentering, int *varDataTypes,
void *vars, int nDims, int *dims, int *iBlock, int *nBlocks);
void XDMF_WRITER_API HdfPutUcdMultiMesh(HDFFile *hdfFile,
int coordDataType, float *coords, int nCoords, int *connectivity,
int connectivityLength, int iBlock, int nBlocks);
void XDMF_WRITER_API HdfPutUcdMultiVar(HDFFile *hdfFile, int nVars,
char **varNames, int *varTypes, int *varCentering, int *varDataTypes,
void *vars, int nDims, int nCoords, int nCells, int iBlock, int nBlocks);
void XDMF_WRITER_API HdfParallelClose(HDFFile *hdfFile);
XDMFFile XDMF_WRITER_API *XdmfCreate(const char *fileName, double time);
......@@ -98,7 +109,7 @@ void XDMF_WRITER_API XdmfWriteCurvVar(XDMFFile *file, const char *gridFileName,
int *varCentering, int *varDataTypes, int nDims, int *dims);
void XDMF_WRITER_API XdmfPutUcdGrid(XDMFFile *file, const char *gridFileName,
const char *varFileName, const char *gridName, const char *coordName,
int coordDataType, int nCoords, int coordDim, const char *connectivityName,
int coordDataType, int nCoords, int coordDims, const char *connectivityName,
int cellType, int nCells, int connectivityLength, int nVars,
char **varNames, int *varTypes, int *varCentering, int *varDataTypes);
void XDMF_WRITER_API XdmfStartMultiBlock(XDMFFile *xdmfFile,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment