main.cpp 1.97 KB
Newer Older
1
2
3
4
5
6
7
8
#include <mpi.h>

#define MPI_CHK(expr) \
	if (expr != MPI_SUCCESS) \
	{ \
		fprintf(stderr, "Error in MPI function %s: %d\n", __FILE__, __LINE__); \
	}

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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"
25
26

#ifdef WITH_OPENMP
27
#include <omp.h>
28
#endif
29

30
31
32
33
34
35
36
37
#ifdef WITH_MPI
int mpi_rank;
int mpi_size;
#else
const int mpi_rank = 0;
const int mpi_size = 1;
#endif

38
39
40
41
#include "cmodules/timer.h"

int main(int argc, char* argv[])
{
David Rohr's avatar
David Rohr committed
42
43
44
	// **************************************************************************************
	// *********************************  Main BioEM code **********************************
	// ************************************************************************************
45

46
47
48
49
50
51
#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

52
#ifdef _MM_DENORMALS_ZERO_ON
53
	#pragma omp parallel
54
55
56
	{
		_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); //Flush denormals to zero in all OpenMP threads
	}
57
#endif
58
	HighResTimer timer;
59

60
	bioem* bio;
61
#ifdef WITH_CUDA
62
63
	if (getenv("GPU") && atoi(getenv("GPU")))
	{
64
		bio = bioem_cuda_create();
65
66
	}
	else
67
#endif
68
69
	{
		bio = new bioem;
70
71
	}

David Rohr's avatar
David Rohr committed
72
	// ************  Configuration and Pre-calculating necessary objects *****************
David Rohr's avatar
David Rohr committed
73
	if (mpi_rank == 0) printf("Configuring\n");
74
75
	if (bio->configure(argc, argv) == 0)
	{
76

77
		// *******************************  Run BioEM routine ******************************
David Rohr's avatar
David Rohr committed
78
		if (mpi_rank == 0) printf("Running\n");
79
80
81
		timer.Start();
		bio->run();
		timer.Stop();
82

83
		// ************************************ End **********************************
David Rohr's avatar
David Rohr committed
84
		printf ("The code ran for %f seconds (rank %d).\n", timer.GetElapsedTime(), mpi_rank);
85
86
		bio->cleanup();
	}
87
	delete bio;
88

89
90
91
92
#ifdef WITH_MPI
	MPI_Finalize();
#endif

93
	return(0);
94
}