/[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 2141 by caltinay, Tue Dec 9 04:32:32 2008 UTC revision 2385 by gross, Wed Apr 15 03:52:38 2009 UTC
# Line 22  Line 22 
22  #include "paso/PasoUtil.h"  #include "paso/PasoUtil.h"
23    
24  #define INT_FORMAT "%d "  #define INT_FORMAT "%d "
25  #define LEN_INT_FORMAT (9+1)  #define LEN_INT_FORMAT (unsigned int)(9+1)
26  #define INT_NEWLINE_FORMAT "%d\n"  #define INT_NEWLINE_FORMAT "%d\n"
27  #define SCALAR_FORMAT "%12.6e\n"  #define SCALAR_FORMAT "%12.6e\n"
28  #define VECTOR_FORMAT "%12.6e %12.6e %12.6e\n"  #define VECTOR_FORMAT "%12.6e %12.6e %12.6e\n"
29  #define TENSOR_FORMAT "%12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n"  #define TENSOR_FORMAT "%12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n"
30  #define LEN_TENSOR_FORMAT (9*(12+1)+1)  #define LEN_TENSOR_FORMAT (unsigned int)(9*(12+1)+1)
31  #define NEWLINE "\n"  #define NEWLINE "\n"
32  #define LEN_TMP_BUFFER LEN_TENSOR_FORMAT+(MAX_numNodes*LEN_INT_FORMAT+1)+2  #define LEN_TMP_BUFFER LEN_TENSOR_FORMAT+(MAX_numNodes*LEN_INT_FORMAT+1)+2
33  #define NCOMP_MAX 9  #define NCOMP_MAX (unsigned int)9
34    
35  #define __STRCAT(dest, chunk, dest_in_use) \  #define __STRCAT(dest, chunk, dest_in_use) \
36  do {\  do {\
# 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 205  void Finley_Mesh_saveVTK(const char *fil Line 209  void Finley_Mesh_saveVTK(const char *fil
209      my_mpi_rank = mesh_p->Nodes->MPIInfo->rank;      my_mpi_rank = mesh_p->Nodes->MPIInfo->rank;
210      mpi_size = mesh_p->Nodes->MPIInfo->size;      mpi_size = mesh_p->Nodes->MPIInfo->size;
211    
212      /************************************************************************/      /************************************************************************
213      /* open the file and check handle */       * open the file and check handle *
214         */
215      if (mpi_size > 1) {      if (mpi_size > 1) {
216  #ifdef PASO_MPI  #ifdef PASO_MPI
217          const int amode = MPI_MODE_CREATE|MPI_MODE_WRONLY|MPI_MODE_UNIQUE_OPEN;          const int amode = MPI_MODE_CREATE|MPI_MODE_WRONLY|MPI_MODE_UNIQUE_OPEN;
# Line 221  void Finley_Mesh_saveVTK(const char *fil Line 225  void Finley_Mesh_saveVTK(const char *fil
225              sprintf(errorMsg, "saveVTK: File %s could not be opened for writing in parallel.", filename_p);              sprintf(errorMsg, "saveVTK: File %s could not be opened for writing in parallel.", filename_p);
226              Finley_setError(IO_ERROR, errorMsg);              Finley_setError(IO_ERROR, errorMsg);
227          } else {          } else {
228              MPI_File_set_view(mpi_fileHandle_p, MPI_DISPLACEMENT_CURRENT,              ierr=MPI_File_set_view(mpi_fileHandle_p,MPI_DISPLACEMENT_CURRENT,
229                      MPI_CHAR, MPI_CHAR, "native", mpi_info);                      MPI_CHAR, MPI_CHAR, "native", mpi_info);
230          }          }
231  #endif /* PASO_MPI */  #endif /* PASO_MPI */
# Line 485  void Finley_Mesh_saveVTK(const char *fil Line 489  void Finley_Mesh_saveVTK(const char *fil
489    
490      /* allocate enough memory for text buffer */      /* allocate enough memory for text buffer */
491    
492      txtBufferSize = strlen(vtkHeader) + 3*LEN_INT_FORMAT + (30+3*maxNameLen);      txtBufferSize = strlen(vtkHeader) + 3*LEN_INT_FORMAT + (30+3*maxNameLen);
   
493      if (mpi_size > 1) {      if (mpi_size > 1) {
494          txtBufferSize = MAX(txtBufferSize, myNumPoints * LEN_TMP_BUFFER);         txtBufferSize = MAX(txtBufferSize, myNumPoints * LEN_TMP_BUFFER);
495          txtBufferSize = MAX(txtBufferSize, numCellFactor * myNumCells *          txtBufferSize = MAX(txtBufferSize, numCellFactor * myNumCells *
496                  (LEN_INT_FORMAT * numVTKNodesPerElement + 1));                  (LEN_INT_FORMAT * numVTKNodesPerElement + 1));
497          txtBufferSize = MAX(txtBufferSize,          txtBufferSize = MAX(txtBufferSize,
# Line 548  void Finley_Mesh_saveVTK(const char *fil Line 551  void Finley_Mesh_saveVTK(const char *fil
551                      }                      }
552                  }                  }
553              } /* nDim */              } /* nDim */
554              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
555    
556              /* write the cells */              /* write the cells */
557              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 581  void Finley_Mesh_saveVTK(const char *fil
581                      }                      }
582                  }                  }
583              } /* nodeIndex */              } /* nodeIndex */
584              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
585    
586              /* write the offsets */              /* write the offsets */
587              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 593  void Finley_Mesh_saveVTK(const char *fil
593                  sprintf(tmpBuffer, INT_NEWLINE_FORMAT, i);                  sprintf(tmpBuffer, INT_NEWLINE_FORMAT, i);
594                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);
595              }              }
596              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
597    
598              /* write element type */              /* write element type */
599              sprintf(tmpBuffer, INT_NEWLINE_FORMAT, cellType);              sprintf(tmpBuffer, INT_NEWLINE_FORMAT, cellType);
# Line 602  void Finley_Mesh_saveVTK(const char *fil Line 605  void Finley_Mesh_saveVTK(const char *fil
605              {              {
606                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);                  __STRCAT(txtBuffer, tmpBuffer, txtBufferInUse);
607              }              }
608              MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);              MPI_WRITE_ORDERED(txtBuffer);
609              /* finalize cell information */              /* finalize cell information */
610              strcpy(txtBuffer, "</DataArray>\n</Cells>\n");              strcpy(txtBuffer, "</DataArray>\n</Cells>\n");
611              MPI_RANK0_WRITE_SHARED(txtBuffer);              MPI_RANK0_WRITE_SHARED(txtBuffer);
# Line 762  void Finley_Mesh_saveVTK(const char *fil Line 765  void Finley_Mesh_saveVTK(const char *fil
765                  txtBufferInUse = 0;                  txtBufferInUse = 0;
766                  for (i=0; i<numCells; i++) {                  for (i=0; i<numCells; i++) {
767                      if (elements->Owner[i] == my_mpi_rank) {                      if (elements->Owner[i] == my_mpi_rank) {
768                          double *values = getSampleData(data_pp[dataIdx], i);              void* sampleBuffer=allocSampleBuffer(data_pp[dataIdx]);
769                            __const double *values = getSampleDataRO(data_pp[dataIdx], i,sampleBuffer);
770                          for (l = 0; l < numCellFactor; l++) {                          for (l = 0; l < numCellFactor; l++) {
771                              double sampleAvg[NCOMP_MAX];                              double sampleAvg[NCOMP_MAX];
772                              dim_t nCompUsed = MIN(nComp, NCOMP_MAX);                              dim_t nCompUsed = MIN(nComp, NCOMP_MAX);
# Line 828  void Finley_Mesh_saveVTK(const char *fil Line 832  void Finley_Mesh_saveVTK(const char *fil
832                                  fputs(tmpBuffer, fileHandle_p);                                  fputs(tmpBuffer, fileHandle_p);
833                              }                              }
834                          } /* for l (numCellFactor) */                          } /* for l (numCellFactor) */
835                freeSampleBuffer(sampleBuffer);
836                      } /* if I am the owner */                      } /* if I am the owner */
837                  } /* for i (numCells) */                  } /* for i (numCells) */
838    
839                  if ( mpi_size > 1) {                  if ( mpi_size > 1) {
840                      MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);                      MPI_WRITE_ORDERED(txtBuffer);
841                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);
842                  } else {                  } else {
843                      fputs(tag_End_DataArray, fileHandle_p);                      fputs(tag_End_DataArray, fileHandle_p);
# Line 943  void Finley_Mesh_saveVTK(const char *fil Line 948  void Finley_Mesh_saveVTK(const char *fil
948                  for (i=0; i<mesh_p->Nodes->numNodes; i++) {                  for (i=0; i<mesh_p->Nodes->numNodes; i++) {
949                      k = globalNodeIndex[i];                      k = globalNodeIndex[i];
950                      if ( (myFirstNode <= k) && (k < myLastNode) ) {                      if ( (myFirstNode <= k) && (k < myLastNode) ) {
951                          double *values = getSampleData(data_pp[dataIdx], nodeMapping->target[i]);              void* sampleBuffer=allocSampleBuffer(data_pp[dataIdx]);
952                            __const double *values = getSampleDataRO(data_pp[dataIdx], nodeMapping->target[i], sampleBuffer);
953                          /* if the number of mpi_required components is more than                          /* if the number of mpi_required components is more than
954                           * the number of actual components, pad with zeros.                           * the number of actual components, pad with zeros.
955                           * Probably only need to get shape of first element */                           * Probably only need to get shape of first element */
# Line 983  void Finley_Mesh_saveVTK(const char *fil Line 989  void Finley_Mesh_saveVTK(const char *fil
989                          } else {                          } else {
990                              fputs(tmpBuffer, fileHandle_p);                              fputs(tmpBuffer, fileHandle_p);
991                          }                          }
992                freeSampleBuffer(sampleBuffer);         /* no-one needs values anymore */
993                      } /* if this is my node */                      } /* if this is my node */
994                  } /* for i (numNodes) */                  } /* for i (numNodes) */
995    
996                  if ( mpi_size > 1) {                  if ( mpi_size > 1) {
997                      MPI_WRITE_ORDERED(txtBuffer, txtBufferInUse);                      MPI_WRITE_ORDERED(txtBuffer);
998                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);                      MPI_RANK0_WRITE_SHARED(tag_End_DataArray);
999                  } else {                  } else {
1000                      fputs(tag_End_DataArray, fileHandle_p);                      fputs(tag_End_DataArray, fileHandle_p);
# Line 1015  void Finley_Mesh_saveVTK(const char *fil Line 1022  void Finley_Mesh_saveVTK(const char *fil
1022      if ( mpi_size > 1) {      if ( mpi_size > 1) {
1023  #ifdef PASO_MPI  #ifdef PASO_MPI
1024          MPI_File_close(&mpi_fileHandle_p);          MPI_File_close(&mpi_fileHandle_p);
1025        MPI_Barrier(mesh_p->Nodes->MPIInfo->comm);
1026  #endif  #endif
1027      } else {      } else {
1028          fclose(fileHandle_p);          fclose(fileHandle_p);

Legend:
Removed from v.2141  
changed lines
  Added in v.2385

  ViewVC Help
Powered by ViewVC 1.1.26