main.cpp 2.64 KB
Newer Older
1
2
3
4
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   < BioEM software for Bayesian inference of Electron Microscopy images>
   Copyright (C) 2016 Pilar Cossio, David Rohr, Fabio Baruffa, Markus Rampp, 
        Volker Lindenstruth and Gerhard Hummer.
Pilar Cossio's avatar
Pilar Cossio committed
5
6
7
8
   
    Max Planck Institute of Biophysics, Frankfurt, Germany.
   Frankfurt Institute for Advanced Studies, Goethe University Frankfurt, Germany.
   Max Planck Computing and Data Facility, Garching, Germany. 
9

Pilar Cossio's avatar
Pilar Cossio committed
10
   Released under the GNU Public License, v3. 
11
12
13
14
   See license statement for terms of distribution.

   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

Pilar Cossio's avatar
Pilar Cossio committed
15
#ifdef WITH_MPI
16
17
18
19
20
21
22
#include <mpi.h>

#define MPI_CHK(expr) \
	if (expr != MPI_SUCCESS) \
	{ \
		fprintf(stderr, "Error in MPI function %s: %d\n", __FILE__, __LINE__); \
	}
Pilar Cossio's avatar
Pilar Cossio committed
23
#endif
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fenv.h>

#ifdef _WIN32
#include <Windows.h>
#include <WinBase.h>
#endif

#include <iostream>
#include <algorithm>
#include <iterator>
#include "bioem.h"
#include "bioem_cuda.h"
41
42

#ifdef WITH_OPENMP
43
#include <omp.h>
44
#endif
45

46
47
48
49
#ifdef WITH_MPI
int mpi_rank;
int mpi_size;
#else
Pilar Cossio's avatar
Pilar Cossio committed
50
51
int mpi_rank = 0;
int mpi_size = 1;
52
53
#endif

54
#include "timer.h"
55
56
57

int main(int argc, char* argv[])
{
David Rohr's avatar
David Rohr committed
58
59
60
	// **************************************************************************************
	// *********************************  Main BioEM code **********************************
	// ************************************************************************************
61

62
63
64
65
66
67
#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

68
#ifdef _MM_DENORMALS_ZERO_ON
69
	#pragma omp parallel
70
71
72
	{
		_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); //Flush denormals to zero in all OpenMP threads
	}
73
#endif
74
	HighResTimer timer;
75

76
	bioem* bio;
77
#ifdef WITH_CUDA
78
79
	if (getenv("GPU") && atoi(getenv("GPU")))
	{
80
		bio = bioem_cuda_create();
81
82
	}
	else
83
#endif
84
85
	{
		bio = new bioem;
86
87
	}

David Rohr's avatar
David Rohr committed
88
	// ************  Configuration and Pre-calculating necessary objects *****************
89
//	if (mpi_rank == 0) printf("Configuring\n");
90
91
	if (bio->configure(argc, argv) == 0)
	{
92

93
		// *******************************  Run BioEM routine ******************************
David Rohr's avatar
David Rohr committed
94
		if (mpi_rank == 0) printf("Running\n");
95
96
97
		timer.Start();
		bio->run();
		timer.Stop();
98

99
		// ************************************ End **********************************
David Rohr's avatar
David Rohr committed
100
		printf ("The code ran for %f seconds (rank %d).\n", timer.GetElapsedTime(), mpi_rank);
101
102
		bio->cleanup();
	}
103
	delete bio;
104

105
106
107
108
#ifdef WITH_MPI
	MPI_Finalize();
#endif

109
	return(0);
110
}