-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
134 lines (115 loc) · 3.31 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
< BioEM software for Bayesian inference of Electron Microscopy images>
Copyright (C) 2017 Pilar Cossio, David Rohr, Fabio Baruffa, Markus Rampp,
Luka Stanisic, Volker Lindenstruth and Gerhard Hummer.
Max Planck Institute of Biophysics, Frankfurt, Germany.
Frankfurt Institute for Advanced Studies, Goethe University Frankfurt,
Germany.
Max Planck Computing and Data Facility, Garching, Germany.
Released under the GNU Public License, v3.
See license statement for terms of distribution.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#ifdef WITH_MPI
#include <mpi.h>
#define MPI_CHK(expr) \
if (expr != MPI_SUCCESS) \
{ \
fprintf(stderr, "Error - MPI function %s: %d\n", __FILE__, __LINE__); \
}
#endif
#include <fenv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef _WIN32
#include <WinBase.h>
#include <Windows.h>
#endif
#include <algorithm>
#include <iostream>
#include <iterator>
#include "bioem.h"
#include "bioem_cuda.h"
#ifdef WITH_OPENMP
#include <omp.h>
#endif
#ifdef WITH_MPI
int mpi_rank;
int mpi_size;
#else
int mpi_rank = 0;
int mpi_size = 1;
#endif
#include "timer.h"
int main(int argc, char *argv[])
{
// **************************************************************************************
// ********************************* Main BioEM code
// **********************************
// ************************************************************************************
#ifdef WITH_MPI
MPI_CHK(MPI_Init(&argc, &argv));
MPI_CHK(MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank));
MPI_CHK(MPI_Comm_size(MPI_COMM_WORLD, &mpi_size));
#endif
#ifdef _MM_DENORMALS_ZERO_ON
#pragma omp parallel
{
_MM_SET_DENORMALS_ZERO_MODE(
_MM_DENORMALS_ZERO_ON); // Flush denormals to zero in all OpenMP threads
}
#endif
HighResTimer timer;
bioem *bio;
#ifdef WITH_CUDA
if (getenv("GPU") && atoi(getenv("GPU")))
{
bio = bioem_cuda_create();
}
else
#endif
{
bio = new bioem;
}
// ************ Configuration and Pre-calculating necessary objects
// *****************
if (mpi_rank == 0)
printf("Configuring\n");
if (bio->configure(argc, argv) == 0)
{
if (bio->needToPrintModel())
{
if (mpi_size == 1)
{
bio->printModel();
}
else
{
myError("Model printing can be performed only if using a single "
"MPI process. Please change your execution to use a single MPI "
"process or no MPI at all");
}
}
else
{
// ******************************* Run BioEM routine
// ******************************
if (mpi_rank == 0)
printf("Running\n");
timer.Start();
bio->run();
timer.Stop();
// ************************************ End
// **********************************
printf("The code ran for %f seconds (rank %d).\n", timer.GetElapsedTime(),
mpi_rank);
bio->cleanup();
}
}
delete bio;
#ifdef WITH_MPI
MPI_Finalize();
#endif
return (0);
}