-
Notifications
You must be signed in to change notification settings - Fork 2
/
project2_Delaunoy_Crasset_MAIN.c
91 lines (75 loc) · 2.4 KB
/
project2_Delaunoy_Crasset_MAIN.c
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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <mpi.h>
#include "project2_Delaunoy_Crasset_IO.h"
#include "project2_Delaunoy_Crasset_IMPLICIT.h"
#include "project2_Delaunoy_Crasset_EXPLICIT.h"
#define M_PI 3.14159265358979323846
int main(int argc, char* argv[]) {
// Check number of arguments
assert(argc >= 4);
const char* parameter_file = argv[1];
const char* map_file = argv[2];
const unsigned int scheme = atoi(argv[3]);
//Check argument validity
assert((scheme == 0) || (scheme == 1));
// Init MPI
int nbproc, myrank;
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided);
if(provided != MPI_THREAD_FUNNELED){
fprintf(stderr, "wrong provided = %d", provided);
}
MPI_Comm_size(MPI_COMM_WORLD, &nbproc);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
// Measure execution time
double startTime = MPI_Wtime();
// Read parameters and map
Parameters* params = readParameterFile(parameter_file);
Map* map = readMapFile(map_file);
// Explicit
if (scheme == 0) {
double** eta;
double** u;
double** v;
int status = eulerExplicitMPI(map, params, &eta, &u, &v);
if(status == -1){
fprintf(stderr, "Error in euler function\n");
free(params);
free(map->grid);
free(map);
MPI_Finalize();
exit(EXIT_FAILURE);
}
}
// Implicit
else {
double* eta;
double* u;
double* v;
if(eulerImplicitMPI(map, params, &eta, &u, &v) == -1){
fprintf(stderr, "error in euler function\n");
free(params);
free(map->grid);
free(map);
MPI_Finalize();
exit(EXIT_FAILURE);
}
}
// Mesure execution time
double endTime = MPI_Wtime();
double executionTime = endTime - startTime;
char* openMP_nbthreads = getenv("OMP_NUM_THREADS");
// Print statistics to standard output (for later analysis)
fprintf(stdout,"%d,%d,%d,%s,%lf,%lf,%lf,%lf,%u,%lf\n", scheme, myrank, nbproc, \
openMP_nbthreads, executionTime, params->deltaX, params->deltaY, \
params->deltaT, params->s, params->r_threshold);
MPI_Finalize();
return 0;
}