/[escript]/trunk/finley/src/Mesh_saveVTK.c
ViewVC logotype

Diff of /trunk/finley/src/Mesh_saveVTK.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2310 by gross, Mon Mar 16 04:07:43 2009 UTC revision 2548 by jfenwick, Mon Jul 20 06:20:06 2009 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*******************************************************
3  *  *
4  * Copyright (c) 2003-2008 by University of Queensland  * Copyright (c) 2003-2009 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * Earth Systems Science Computational Center (ESSCC)
6  * http://www.uq.edu.au/esscc  * http://www.uq.edu.au/esscc
7  *  *
# Line 39  do {\ Line 39  do {\
39  } while(0)  } while(0)
40    
41  #ifdef PASO_MPI  #ifdef PASO_MPI
   
42  /* writes buffer to file catching the empty buffer case which causes problems  /* writes buffer to file catching the empty buffer case which causes problems
43   * with some MPI versions */   * with some MPI versions */
44  #define MPI_WRITE_ORDERED(BUF, LEN) \  #define MPI_WRITE_ORDERED(BUF) \
45  do {\  do {\
46      if (LEN==0) { strcpy(BUF, " "); LEN=1; }\      int LLEN=0; \
47      MPI_File_write_ordered(mpi_fileHandle_p, BUF, LEN, MPI_CHAR, &mpi_status);\      LLEN=(int) strlen(BUF); \
48        if (LLEN==0) { strcpy(BUF, ""); LLEN=0; }\
49        MPI_File_write_ordered(mpi_fileHandle_p, BUF, LLEN, MPI_CHAR, &mpi_status);\
50  } while(0)  } while(0)
51    
52  /* writes buffer to file on master only */  /* writes buffer to file on master only */
53  #define MPI_RANK0_WRITE_SHARED(BUF) \  #define MPI_RANK0_WRITE_SHARED(BUF) \
54  do {\  do {\
55        int LLEN=0; \
56      if (my_mpi_rank == 0) {\      if (my_mpi_rank == 0) {\
57          MPI_File_iwrite_shared(mpi_fileHandle_p, BUF, strlen(BUF), MPI_CHAR, &mpi_req);\          LLEN=(int) strlen(BUF); \
58            if (LLEN==0) { strcpy(BUF,""); LLEN=0; }\
59            MPI_File_iwrite_shared(mpi_fileHandle_p, BUF, LLEN, MPI_CHAR, &mpi_req);\
60          MPI_Wait(&mpi_req, &mpi_status);\          MPI_Wait(&mpi_req, &mpi_status);\
61      }\      }\
62  } while(0)  } while(0)
# Line 75  void create_MPIInfo(MPI_Info& info) Line 79  void create_MPIInfo(MPI_Info& info)
79    
80  #else  #else
81    
82  #define MPI_WRITE_ORDERED(A, B)  #define MPI_WRITE_ORDERED(A)
83  #define MPI_RANK0_WRITE_SHARED(A)  #define MPI_RANK0_WRITE_SHARED(A)
84    
85  #endif /* PASO_MPI */  #endif /* PASO_MPI */
# Line 138  void Finley_Mesh_saveVTK(const char *fil Line 142  void Finley_Mesh_saveVTK(const char *fil
142                           Finley_Mesh *mesh_p,                           Finley_Mesh *mesh_p,
143                           const dim_t num_data,                           const dim_t num_data,
144                           char **names_p,                           char **names_p,
145                           escriptDataC **data_pp)                           escriptDataC **data_pp,
146                             const char* metadata,
147                             const char*metadata_schema)
148  {  {
149  #ifdef PASO_MPI  #ifdef PASO_MPI
150      MPI_File mpi_fileHandle_p;      MPI_File mpi_fileHandle_p;
# Line 167  void Finley_Mesh_saveVTK(const char *fil Line 173  void Finley_Mesh_saveVTK(const char *fil
173    
174      const char *vtkHeader = \      const char *vtkHeader = \
175        "<?xml version=\"1.0\"?>\n" \        "<?xml version=\"1.0\"?>\n" \
176        "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\">\n" \        "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\"%s%s>\n%s%s" \
177        "<UnstructuredGrid>\n" \        "<UnstructuredGrid>\n" \
178        "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n" \        "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n" \
179        "<Points>\n" \        "<Points>\n" \
# Line 485  void Finley_Mesh_saveVTK(const char *fil Line 491  void Finley_Mesh_saveVTK(const char *fil
491    
492      /* allocate enough memory for text buffer */      /* allocate enough memory for text buffer */
493    
494      txtBufferSize = strlen(vtkHeader) + 3*LEN_INT_FORMAT + (30+3*maxNameLen);      txtBufferSize = strlen(vtkHeader) + 3*LEN_INT_FORMAT + (30+3*maxNameLen)+strlen(metadata)+strlen(metadata_schema);
   
495      if (mpi_size > 1) {      if (mpi_size > 1) {
496         txtBufferSize = MAX(txtBufferSize, myNumPoints * LEN_TMP_BUFFER);         txtBufferSize = MAX(txtBufferSize, myNumPoints * LEN_TMP_BUFFER);
497          txtBufferSize = MAX(txtBufferSize, numCellFactor * myNumCells *          txtBufferSize = MAX(txtBufferSize, numCellFactor * myNumCells *
# Line 519  void Finley_Mesh_saveVTK(const char *fil Line 524  void Finley_Mesh_saveVTK(const char *fil
524              nodeIndex = NULL;              nodeIndex = NULL;
525          }          }
526    
527          sprintf(txtBuffer, vtkHeader, globalNumPoints,          if (strlen(metadata)>0) {
528                  numCellFactor*globalNumCells, 3);             if (strlen(metadata_schema)>0) {
529                  sprintf(txtBuffer, vtkHeader," ",metadata_schema,metadata,"\n",globalNumPoints, numCellFactor*globalNumCells, 3);
530               } else {
531                  sprintf(txtBuffer, vtkHeader,"","",metadata,"\n",globalNumPoints, numCellFactor*globalNumCells, 3);
532               }
533            } else {
534               if (strlen(metadata_schema)>0) {
535                  sprintf(txtBuffer, vtkHeader," ",metadata_schema,"","",globalNumPoints, numCellFactor*globalNumCells, 3);
536               } else {
537                  sprintf(txtBuffer, vtkHeader,"","","","",globalNumPoints, numCellFactor*globalNumCells, 3);
538               }
539            }
540    
541          if (mpi_size > 1) {          if (mpi_size > 1) {
542              /* write the nodes */              /* write the nodes */
# Line 548  void Finley_Mesh_saveVTK(const char *fil Line 564  void Finley_Mesh_saveVTK(const char *fil
564                      }                      }
565                  }                  }
566              } /* nDim */              } /* nDim */
567              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
568    
569              /* write the cells */              /* write the cells */
570              MPI_RANK0_WRITE_SHARED(tags_End_Points_and_Start_Conn);              MPI_RANK0_WRITE_SHARED(tags_End_Points_and_Start_Conn);
# Line 578  void Finley_Mesh_saveVTK(const char *fil Line 594  void Finley_Mesh_saveVTK(const char *fil
594                      }                      }
595                  }                  }
596              } /* nodeIndex */              } /* nodeIndex */
597              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
598    
599              /* write the offsets */              /* write the offsets */
600              MPI_RANK0_WRITE_SHARED(tags_End_Conn_and_Start_Offset);              MPI_RANK0_WRITE_SHARED(tags_End_Conn_and_Start_Offset);
# Line 590  void Finley_Mesh_saveVTK(const char *fil Line 606  void Finley_Mesh_saveVTK(const char *fil
606                  sprintf(tmpBuffer, INT_NEWLINE_FORMAT, i);                  sprintf(tmpBuffer, INT_NEWLINE_FORMAT, i);
607                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);
608              }              }
609              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
610    
611              /* write element type */              /* write element type */
612              sprintf(tmpBuffer, INT_NEWLINE_FORMAT, cellType);              sprintf(tmpBuffer, INT_NEWLINE_FORMAT, cellType);
# Line 602  void Finley_Mesh_saveVTK(const char *fil Line 618  void Finley_Mesh_saveVTK(const char *fil
618              {              {
619                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);
620              }              }
621              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
622              /* finalize cell information */              /* finalize cell information */
623              strcpy(txtBuffer, "</DataArray>\n</Cells>\n");              strcpy(txtBuffer, "</DataArray>\n</Cells>\n");
624              MPI_RANK0_WRITE_SHARED(txtBuffer);              MPI_RANK0_WRITE_SHARED(txtBuffer);
# Line 834  void Finley_Mesh_saveVTK(const char *fil Line 850  void Finley_Mesh_saveVTK(const char *fil
850                  } /* for i (numCells) */                  } /* for i (numCells) */
851    
852                  if ( mpi_size > 1) {                  if ( mpi_size > 1) {
853                      MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);                      MPI_WRITE_ORDERED(txtBuffer);
854                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);
855                  } else {                  } else {
856                      fputs(tag_End_DataArray, fileHandle_p);                      fputs(tag_End_DataArray, fileHandle_p);
# Line 991  void Finley_Mesh_saveVTK(const char *fil Line 1007  void Finley_Mesh_saveVTK(const char *fil
1007                  } /* for i (numNodes) */                  } /* for i (numNodes) */
1008    
1009                  if ( mpi_size > 1) {                  if ( mpi_size > 1) {
1010                      MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);                      MPI_WRITE_ORDERED(txtBuffer);
1011                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);
1012                  } else {                  } else {
1013                      fputs(tag_End_DataArray, fileHandle_p);                      fputs(tag_End_DataArray, fileHandle_p);

Legend:
Removed from v.2310  
changed lines
  Added in v.2548

  ViewVC Help
Powered by ViewVC 1.1.26