LatticeYangMills
outputconf.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * MIT License
4 *
5 * Copyright (c) 2018 Giovanni Pederiva
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 ******************************************************************************/
25 
34 #include <boost/filesystem.hpp>
35 #include "Utils/clusterspecifier.h"
36 #ifndef LACONIA
37 #include <mpi/mpi.h>
38 #else
39 #include <mpi.h>
40 #endif
41 #include <cstdio>
42 
43 #include "InputOutput/outputconf.h"
44 #include "Math/lattice.h"
45 #include "ParallelTools/parallel.h"
46 
47 
48 namespace LatticeIO {
49 
50 
51  int OutputConf::m_linkSize = 72 * sizeof(double);
52  std::string OutputConf::m_outputDir;
53 
58  void OutputConf::setOutputDir(std::string outputDir){
59  m_outputDir = outputDir;
60  boost::filesystem::create_directory(m_outputDir);
61  }
62 
63  // // Write a single file for every sublattice (for testing)
64  // void OutputConf::writeSubLattice(GluonField& lattice, int confNum){
65  // char fileName [1024];
66  // sprintf(fileName, "%s/r%03du%03d", m_outputDir.c_str(), Parallel::rank(), confNum);
67  // FILE* output = fopen(fileName, "wb");
68  // for(int t = 0; t < Parallel::latticeSubSize()[3]; t++){
69  // for(int z = 0; z < Parallel::latticeSubSize()[2]; z++){
70  // for(int y = 0; y < Parallel::latticeSubSize()[1]; y++){
71  // for(int x = 0; x < Parallel::latticeSubSize()[0]; x++){
72  // //fwrite(lattice(x,y,z,t).m_links, sizeof(double), 72, output);
73  // }}}}
74  // fclose(output);
75  // }
76  void OutputConf::writeConf(GluonField& lattice, int confNum){
82  MPI_File output;
83  MPI_Offset startPointT, startPointZ, startPointY, startPointX;
84  int volumeX = 1;
85  int volumeY = Parallel::latticeFullSize()[0] * volumeX;
86  int volumeZ = Parallel::latticeFullSize()[1] * volumeY;
87  int volumeT = Parallel::latticeFullSize()[2] * volumeZ;
88 
89  // Create filename and open
90  char fileName [1024];
91  sprintf(fileName, "%s/conf%04d.bin", m_outputDir.c_str(), confNum);
92  Parallel::openFile(output, fileName);
93 
94  for(int t = 0; t < Parallel::latticeSubSize()[3]; t++){
95  startPointT = volumeT * ( Parallel::rankCoord()[3]*Parallel::latticeSubSize()[3] + t);
96  for(int z = 0; z < Parallel::latticeSubSize()[2]; z++){
97  startPointZ = startPointT + volumeZ * ( Parallel::rankCoord()[2]*Parallel::latticeSubSize()[2] + z);
98  for(int y = 0; y < Parallel::latticeSubSize()[1]; y++){
99  startPointY = startPointZ + volumeY * ( Parallel::rankCoord()[1]*Parallel::latticeSubSize()[1] + y);
100  for(int x = 0; x < Parallel::latticeSubSize()[0]; x++){
101  startPointX = startPointY + volumeX * ( Parallel::rankCoord()[0]*Parallel::latticeSubSize()[0] + x);
102  startPointX *= m_linkSize;
103  //MPI_File_write_at(output, startPointX, lattice(x,y,z,t).m_links, 72, MPI_DOUBLE, MPI_STATUS_IGNORE);
104  }
105  }
106  }
107  }
108  Parallel::closeFile(output);
109  }
110 
111 } // end LatticeIO
Contains the definition of the Lattice class.
static void setOutputDir(std::string outputDir)
Sets the output directory path.
Definition: outputconf.cpp:58
Class that represents the QCD field as an array of 4 SU3 lattices.
Definition: field.h:53
static int m_linkSize
Contains the size in bytes of a 4 links on a lattice site.
Definition: outputconf.h:64
static std::string m_outputDir
The path of the output directory.
Definition: outputconf.h:66
Contains classes for saving lattices to binary files.
Utilities for parallelization.
static void closeFile(MPI_File &file)
closes a file with MPI
Definition: parallel.cpp:156
static void writeConf(GluonField &lattice, int confNum)
Saves the given GluonField object to the ouput directory.
Definition: outputconf.cpp:81
static void openFile(MPI_File &file, const char *fileName)
opens a file with MPI
Definition: parallel.cpp:148