Xmipp  v3.23.11-Nereus
Macros | Functions | Variables
mpi_write_test.cpp File Reference
#include "parallel/xmipp_mpi.h"
#include "core/xmipp_image.h"
#include "core/xmipp_image_generic.h"
Include dependency graph for mpi_write_test.cpp:

Go to the source code of this file.

Macros

#define CREATE_LOG()   FILE * _logML = fopen(formatString("nodo%02d.log", node->rank).c_str(), "w+")
 
#define LOG(msg)   do{fprintf(_logML, "%s\t%s\n", getCurrentTimeString(), msg); fflush(_logML); }while(0)
 
#define CLOSE_LOG()   fclose(_logML)
 
#define IS_MASTER   (node->rank == 0)
 

Functions

int main (int argc, char **argv)
 

Variables

ParallelTaskDistributordistributor
 
MpiNodenode
 

Macro Definition Documentation

◆ CLOSE_LOG

#define CLOSE_LOG ( )    fclose(_logML)

Definition at line 50 of file mpi_write_test.cpp.

◆ CREATE_LOG

#define CREATE_LOG ( )    FILE * _logML = fopen(formatString("nodo%02d.log", node->rank).c_str(), "w+")

Definition at line 48 of file mpi_write_test.cpp.

◆ IS_MASTER

#define IS_MASTER   (node->rank == 0)

Definition at line 52 of file mpi_write_test.cpp.

◆ LOG

#define LOG (   msg)    do{fprintf(_logML, "%s\t%s\n", getCurrentTimeString(), msg); fflush(_logML); }while(0)

Definition at line 49 of file mpi_write_test.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 63 of file mpi_write_test.cpp.

64 {
65  FileName fnIN="test_delete_me.mrcs";
66  int xDim = 64;
67  int yDim = 64;
68  int nDim = 1024;
69  for (int i = 1; i < argc; i++) /* Skip argv[0] (program name). */
70  {
71  if (strcmp(argv[i], "-i") == 0) /* Process optional arguments. */
72  {
73  i++;
74  fnIN =argv[i];
75  }
76  else if (strcmp(argv[i], "--xdim") == 0) /* Process optional arguments. */
77  {
78  i++;
79  xDim = atoi(argv[i]);
80  }
81  else if (strcmp(argv[i], "--ydim") == 0) /* Process optional arguments. */
82  {
83  i++;
84  yDim = atoi(argv[i]);
85  }
86  else if (strcmp(argv[i], "--ndim") == 0) /* Process optional arguments. */
87  {
88  i++;
89  nDim = atoi(argv[i]);
90  }
91 
92  }
93 
94  //First argument should be the md filename
95  //FileName fn(argv[1]);
96  MetaDataVec md;
97  //MPI Initialization
98  node = new MpiNode(argc, argv);
99  int rank = node->rank;
100  int size = node->size;
102  //create blank file
103  if(rank==0)
104  {
105  unlink(fnIN.c_str());
106  createEmptyFile(fnIN, xDim, yDim, 1, nDim);
107  }
108  Image<double> Iaux(xDim,yDim);
109  //Be sure all sync here
111  node->barrierWait();
112 
113  // if (IS_MASTER)
114  for (int var = 1; var <= nDim; var++)
115  {
116  if(var%size==rank)
117  {
118  String ss = formatString("%03d@%s", var,fnIN.c_str());
119  std::cerr << "ssIN: value" << ss << " " << (double)rank << std::endl;
120  Iaux().initConstant((double)rank);
121  node->barrierWait();
122  Iaux.write(ss);
123  }
124  }
125  node->barrierWait();
126  //check results:
127  if(rank==0)
128  {
129  int errors=0;
130  for (int var = 1; var <= nDim; var++)
131  {
132  double value = (double) (var%size);
133  String ss = formatString("%03d@%s", var,fnIN.c_str());
134  Iaux.read(ss.c_str());
135  double min,max,std, avg=0.;
136  Iaux().computeStats(avg,std,min,max);
137  if (
138  ABS(avg-value)> 0.00001 ||
139  ABS(std-0)> 0.00001 ||
140  ABS(min-value)> 0.00001 ||
141  ABS(max-value)> 0.00001
142  ){
143  errors++;
144  std::cerr << "Error in image :" << var
145  << " avg " << avg
146  << " std " << std
147  << " min " << min
148  << " max " << max
149  << std::endl;}
150  }
151  std::cerr << "errors:" << errors << std::endl;
152  }
153 
156  delete node;
157  return 0;
158 }
size_t size
Definition: xmipp_mpi.h:52
void min(Image< double > &op1, const Image< double > &op2)
#define yDim
Definition: projection.cpp:42
#define xDim
Definition: projection.cpp:41
void barrierWait()
Definition: xmipp_mpi.cpp:171
#define i
MpiNode * node
void max(Image< double > &op1, const Image< double > &op2)
#define ABS(x)
Definition: xmipp_macros.h:142
void createEmptyFile(const FileName &filename, int xdim, int ydim, int Zdim, size_t select_img, bool isStack, int mode, int _swapWrite, const MDRowVec *md)
size_t rank
Definition: xmipp_mpi.h:52
std::string String
Definition: xmipp_strings.h:34
String formatString(const char *format,...)

Variable Documentation

◆ distributor

Definition at line 54 of file mpi_write_test.cpp.

◆ node

MpiNode* node

Definition at line 55 of file mpi_write_test.cpp.