Xmipp  v3.23.11-Nereus
mpi_volumeset_align.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Mohamad Harastani mohamad.harastani@upmc.fr
4  * Slavica Jonic slavica.jonic@upmc.fr
5  * Carlos Oscar Sanchez Sorzano coss.eps@ceu.es
6  *
7  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
8  * Lab. de Bioingenieria, Univ. San Pablo CEU
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23  * 02111-1307 USA
24  *
25  * All comments concerning this program package may be sent to the
26  * e-mail address 'xmipp@cnb.uam.es'
27  ***************************************************************************/
28 #include "mpi_volumeset_align.h"
29 
30 // Redefine read to initialize MPI environment =======================
31 void MpiProgVolumeSetAlign::read(int argc, char **argv, bool )
32 {
33  node = std::make_shared<MpiNode>(argc, argv);
34  if (!node->isMaster())
35  verbose=0;
36  fileMutex = std::make_shared<MpiFileMutex>(node);
37  ProgVolumeSetAlign::read(argc, argv);
38 }
39 
40 
41 // Main body ==========================================================
42 void MpiProgVolumeSetAlign::createWorkFiles()
43 {
44  //Master node should prepare some stuff before start working
45  MetaData &mdIn = *getInputMd(); //get a reference to input metadata
46  const char* list_of_volumes = "/WorkingOnThese.xmd";
47  if (node->isMaster()){
49  mdIn.write(fnOutDir + list_of_volumes);
50  }
51  node->barrierWait();//Sync all before start working
52  mdIn.read(fnOutDir + list_of_volumes);
53  mdIn.findObjects(imgsId);//get objects ids
54  distributor = std::make_shared<MpiTaskDistributor>(mdIn.size(), 1, node);
55 }
56 
57 
58 // Only master do starting progress bar stuff
59 void MpiProgVolumeSetAlign::startProcessing()
60 {
61  if (node->isMaster())
63 }
64 
65 //Only master show progress
66 void MpiProgVolumeSetAlign::showProgress()
67 {
68  if (node->isMaster())
70 }
71 
72 // Now use the distributor to grasp images
73 bool MpiProgVolumeSetAlign::getImageToProcess(size_t &objId, size_t &objIndex)
74 {
75  size_t first;
76  size_t last;
77  bool moreTasks = distributor->getTasks(first, last);
78 
79  if (moreTasks){
80  time_bar_done = first + 1;
81  objIndex = first;
82  objId = imgsId[first];
83  return true;
84  }
86  objId = BAD_OBJID;
87  objIndex = BAD_INDEX;
88  return false;
89 }
90 
91 void MpiProgVolumeSetAlign::finishProcessing()
92 {
93  distributor->wait();
94  //All nodes wait for each other
95  node->barrierWait();
96  if (node->isMaster())
98  node->barrierWait();
99 }
100 
101 void MpiProgVolumeSetAlign:: writeVolumeParameters(const FileName &fnImg)
102 {
103  fileMutex->lock();
105  fileMutex->unlock();
106 }
#define BAD_INDEX
Definition: metadata_base.h:56
virtual void read(int argc, const char **argv, bool reportErrors=true)
virtual void writeVolumeParameters(const FileName &fnImg)
virtual void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const =0
void read(int argc, char **argv, bool reportErrors=true) override
glob_log first
int argc
Original command line arguments.
Definition: xmipp_program.h:86
const char ** argv
Definition: xmipp_program.h:87
virtual void finishProcessing()
virtual void findObjects(std::vector< size_t > &objectsOut, const MDQuery &query) const =0
int verbose
Verbosity level.
virtual size_t size() const =0
virtual void createWorkFiles()
FileName fnOutDir
Output directory.
virtual void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true)=0
#define BAD_OBJID
Definition: metadata_base.h:55