Newer
Older
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
#ifndef __HEAT_H__
#define __HEAT_H__
/* Datatype for temperature field */
typedef struct {
/* nx and ny are the true dimensions of the field. The array data
* contains also ghost layers, so it will have dimensions nx+2 x ny+2 */
int nx; /* Local dimensions of the field */
int ny;
int nx_full; /* Global dimensions of the field */
int ny_full; /* Global dimensions of the field */
double dx;
double dy;
double *data;
} field;
/* Datatype for basic parallelization information */
typedef struct {
int size; /* Number of MPI tasks */
int rank;
int nup, ndown, nleft, nright; /* Ranks of neighbouring MPI tasks */
MPI_Comm comm; /* Cartesian communicator */
MPI_Request requests[8]; /* Requests for non-blocking communication */
MPI_Datatype rowtype; /* MPI Datatype for communication of rows */
MPI_Datatype columntype; /* MPI Datatype for communication of columns */
MPI_Datatype subarraytype; /* MPI Datatype for communication in text I/O */
MPI_Datatype restarttype; /* MPI Datatype for communication in restart I/O */
MPI_Datatype filetype; /* MPI Datatype for file view in restart I/O */
} parallel_data;
/* We use here fixed grid spacing */
#define DX 0.01
#define DY 0.01
/* file name for restart checkpoints*/
#define CHECKPOINT "HEAT_RESTART.dat"
/* Inline function for indexing the 2D arrays */
static inline int idx(int i, int j, int width)
{
return i * width + j;
}
/* Function prototypes */
double *malloc_2d(int nx, int ny);
void free_2d(double *array);
void set_field_dimensions(field *temperature, int nx, int ny,
parallel_data *parallel);
void parallel_setup(parallel_data *parallel, int nx, int ny);
void initialize(int argc, char *argv[], field *temperature1,
field *temperature2, int *nsteps, parallel_data *parallel,
int *iter0);
void generate_field(field *temperature, parallel_data *parallel);
void exchange_init(field *temperature, parallel_data *parallel);
void exchange_finalize(parallel_data *parallel);
void evolve_interior(field *curr, field *prev, double a, double dt);
void evolve_edges(field *curr, field *prev, double a, double dt);
void write_field(field *temperature, int iter, parallel_data *parallel);
void read_field(field *temperature1, field *temperature2,
char *filename, parallel_data *parallel);
void write_restart(field *temperature, parallel_data *parallel, int iter);
void read_restart(field *temperature, parallel_data *parallel, int *iter);
void copy_field(field *temperature1, field *temperature2);
void swap_fields(field *temperature1, field *temperature2);
void allocate_field(field *temperature);
void deallocate_field(field *temperature);
void finalize(field *temperature1, field *temperature2,
parallel_data *parallel);
#endif /* __HEAT_H__ */