~ubuntu-branches/ubuntu/vivid/relion/vivid

« back to all changes in this revision

Viewing changes to src/particle_sorter_mpi.cpp

  • Committer: Package Import Robot
  • Author(s): Roland Fehrenbacher
  • Date: 2014-10-23 11:52:48 UTC
  • Revision ID: package-import@ubuntu.com-20141023115248-m3y48dxwl8sqxv9d
Tags: upstream-1.3+dfsg
ImportĀ upstreamĀ versionĀ 1.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *
 
3
 * Author: "Sjors H.W. Scheres"
 
4
 * MRC Laboratory of Molecular Biology
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * This complete copyright notice must be included in any revised version of the
 
17
 * source code. Additional authorship citations may be added, but existing
 
18
 * author citations must be preserved.
 
19
 ***************************************************************************/
 
20
#include "src/particle_sorter_mpi.h"
 
21
 
 
22
void ParticleSorterMpi::read(int argc, char **argv)
 
23
{
 
24
    // Define a new MpiNode
 
25
    node = new MpiNode(argc, argv);
 
26
 
 
27
    // First read in non-parallelisation-dependent variables
 
28
    ParticleSorter::read(argc, argv);
 
29
 
 
30
    // Don't put any output to screen for mpi slaves
 
31
    verb = (node->isMaster()) ? 1 : 0;
 
32
 
 
33
    // Possibly also read parallelisation-dependent variables here
 
34
 
 
35
    // Print out MPI info
 
36
        printMpiNodesMachineNames(*node);
 
37
 
 
38
 
 
39
}
 
40
void ParticleSorterMpi::run()
 
41
{
 
42
 
 
43
        int total_nr_images = MDin.numberOfObjects();
 
44
        features.resize(total_nr_images, NR_FEATURES);
 
45
 
 
46
        // Each node does part of the work
 
47
        long int my_first_image, my_last_image, my_nr_images;
 
48
        divide_equally(total_nr_images, node->size, node->rank, my_first_image, my_last_image);
 
49
        my_nr_images = my_last_image - my_first_image + 1;
 
50
 
 
51
        int barstep;
 
52
        if (verb > 0)
 
53
        {
 
54
                std::cout << "Calculating sorting features for all input particles..." << std::endl;
 
55
                init_progress_bar(my_nr_images);
 
56
                barstep = XMIPP_MAX(1, my_nr_images/ 60);
 
57
        }
 
58
 
 
59
        long int ipart = 0;
 
60
        FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDin)
 
61
        {
 
62
 
 
63
                if (ipart >= my_first_image && ipart <= my_last_image)
 
64
                {
 
65
                        if (verb > 0 && ipart % barstep == 0)
 
66
                                progress_bar(ipart);
 
67
 
 
68
                        calculateFeaturesOneParticle(ipart);
 
69
 
 
70
                }
 
71
                ipart++;
 
72
        }
 
73
 
 
74
        if (verb > 0)
 
75
                progress_bar(my_nr_images);
 
76
 
 
77
        // Combine results from all nodes
 
78
        MultidimArray<double> allnodes_features;
 
79
        allnodes_features.resize(features);
 
80
        MPI_Allreduce(MULTIDIM_ARRAY(features), MULTIDIM_ARRAY(allnodes_features), MULTIDIM_SIZE(features), MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
 
81
        features = allnodes_features;
 
82
 
 
83
        // Only the master writes out files
 
84
        if (verb > 0)
 
85
        {
 
86
                normaliseFeatures();
 
87
 
 
88
                writeFeatures();
 
89
        }
 
90
 
 
91
}