Xmipp  v3.23.11-Nereus
mpi_image_rotational_pca.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano coss@cnb.csic.es (2002)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 // Translated from MATLAB code by Yoel Shkolnisky
27 
29 #include <data/mask.h>
31 
32 // Empty constructor =======================================================
34 {
35  node = std::make_shared<MpiNode>(argc, argv);
36  rank = node->rank;
37  if (!IS_MASTER)
38  verbose = 0;
39 }
40 
42 {
43  if (IS_MASTER)
44  {
46  MDin.write(fnRoot + "_temp.xmd");
47  node->barrierWait();
48  node->barrierWait();
49  unlink((fnRoot + "_temp.xmd").c_str());
50  }
51  else
52  {
53  node->barrierWait();
54  MDin.read(fnRoot + "_temp.xmd");
55  node->barrierWait();
56  }
57 }
58 
60 {
61  MPI_Bcast(&MAT_ELEM(W,0,0),MAT_XSIZE(W)*MAT_YSIZE(W),MPI_DOUBLE,0,MPI_COMM_WORLD);
62 }
63 
65 {
66  fileMutex = std::make_unique<MpiFileMutex>(node);
67  threadMutex = std::make_unique<Mutex>();
68  taskDistributor = std::make_unique<MpiTaskDistributor>(Nimgs, XMIPP_MAX(1,Nimgs/(5*node->size)), node);
69 }
70 
73 {
74  MPI_Allreduce(MPI_IN_PLACE, MATRIX2D_ARRAY(Wnode_0), MAT_XSIZE(Wnode_0)*MAT_YSIZE(Wnode_0),
75  MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
76 }
77 
79 {
80  if (IS_MASTER)
82  node->barrierWait();
83  MPI_Bcast(&qrDim,1,MPI_INT,0,MPI_COMM_WORLD);
84 }
85 
87 {
88 // Load the first qrDim columns of F in matrix H
89  if (IS_MASTER)
90  {
92  node->barrierWait();
93  }
94  else
95  {
96  node->barrierWait();
97  H.mapToFile(fnRoot+"_matrixH.raw",MAT_XSIZE(F),qrDim);
98  }
99 }
100 
102 {
103  if (IS_MASTER)
105  node->barrierWait();
106 }
107 
108 // Copy H to F ============================================================
110 {
111  if (IS_MASTER)
113  node->barrierWait();
114 }
115 
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
virtual void copyHtoF(int block)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
virtual void selectPartFromMd(MetaData &MDin)
void mapToFile(const FileName &fn, int Ydim, int Xdim, size_t offset=0)
Definition: matrix2d.cpp:1079
virtual void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const =0
virtual void createMutexes(size_t Nimgs)
virtual void comunicateQrDim(int &qrDim)
std::shared_ptr< MpiNode > node
std::unique_ptr< Mutex > threadMutex
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
int argc
Original command line arguments.
Definition: xmipp_program.h:86
virtual void comunicateQrDim(int &qrDim)
#define IS_MASTER
const char ** argv
Definition: xmipp_program.h:87
std::unique_ptr< ThreadTaskDistributor > taskDistributor
std::unique_ptr< Mutex > fileMutex
int verbose
Verbosity level.
virtual void mapMatrix(int qrDim)
virtual void comunicateMatrix(Matrix2D< double > &W)
virtual void selectPartFromMd(MetaData &MDin)
virtual void mapMatrix(int qrDim)
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
MpiProgImageRotationalPCA(int argc, char **argv)
Empty constructor.
virtual void allReduceApplyT(Matrix2D< double > &Wnode_0)
#define MATRIX2D_ARRAY(m)
Definition: matrix2d.h:89
virtual void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true)=0