engine.h 4.08 KB
Newer Older
Pedro Gonnet's avatar
Pedro Gonnet committed
1
/*******************************************************************************
2
 * This file is part of SWIFT.
Pedro Gonnet's avatar
Pedro Gonnet committed
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
 * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 ******************************************************************************/



/* Some constants. */
#define engine_policy_none          0
#define engine_policy_rand          1
#define engine_policy_steal         2
#define engine_policy_keep          4
#define engine_policy_block         8
28
#define engine_policy_fixdt         16
29
#define engine_policy_multistep     32
30
#define engine_policy_cputight      64
31
32
#define engine_policy_mpi           128
#define engine_policy_setaffinity   256
33
#define engine_policy_paranoid      512
Pedro Gonnet's avatar
Pedro Gonnet committed
34
35

#define engine_queue_scale          1.2
36
#define engine_maxtaskspercell      128
37
#define engine_maxproxies           64
Pedro Gonnet's avatar
Pedro Gonnet committed
38
#define engine_tasksreweight        10
Pedro Gonnet's avatar
Pedro Gonnet committed
39
40


41
42
43
44
/* The rank of the engine as a global variable (for messages). */
extern int engine_rank;


45
46
47
48
49
50
51
52
53
54
55
56
/* Mini struct to link cells to density/force tasks. */
struct link {

    /* The task pointer. */
    struct task *t;
    
    /* The next pointer. */
    struct link *next;
    
    };


Pedro Gonnet's avatar
Pedro Gonnet committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Data structure for the engine. */
struct engine {

    /* Number of threads on which to run. */
    int nr_threads;
    
    /* The space with which the runner is associated. */
    struct space *s;
    
    /* The runner's threads. */
    struct runner *runners;
    
    /* The running policy. */
    int policy;
    
72
73
    /* The task scheduler. */
    struct scheduler sched;
Pedro Gonnet's avatar
Pedro Gonnet committed
74
    
75
76
77
78
    /* The maximum dt to step (current). */
    float dt_step;
    
    /* The minimum dt over all particles in the system. */
79
    float dt_min, dt_max;
80
81
    
    /* The system time step. */
82
    float dt, dt_orig;
83
    
84
85
86
    /* The system energies from the previous step. */
    double ekin, epot;
    
87
    /* The current step number. */
Pedro Gonnet's avatar
Pedro Gonnet committed
88
    int step, nullstep;
89
    
90
91
92
    /* The number of particles updated in the previous step. */
    int count_step;
    
93
94
95
    /* The current system time. */
    float time;
    
Pedro Gonnet's avatar
Pedro Gonnet committed
96
97
98
    /* Data for the threads' barrier. */
    pthread_mutex_t barrier_mutex;
    pthread_cond_t barrier_cond;
99
    volatile int barrier_running, barrier_launch, barrier_launchcount;
Pedro Gonnet's avatar
Pedro Gonnet committed
100
    
101
102
103
104
105
106
    /* ID of the node this engine lives on. */
    int nr_nodes, nodeID;
    
    /* Proxies for the other nodes in this simulation. */
    struct proxy *proxies;
    int nr_proxies, *proxy_ind;
107
108
109

    /* Tic at the start of a step. */
    ticks tic_step;
110
    
111
112
113
    /* Force the engine to rebuild? */
    int forcerebuild, forcerepart;
    
Pedro Gonnet's avatar
Pedro Gonnet committed
114
115
116
    /* How many steps have we done with the same set of tasks? */
    int tasks_age;
    
117
118
119
120
    /* Linked list for cell-task association. */
    struct link *links;
    int nr_links;
    
Pedro Gonnet's avatar
Pedro Gonnet committed
121
122
123
124
    };


/* Function prototypes. */
125
void engine_barrier( struct engine *e , int tid );
126
void engine_init ( struct engine *e , struct space *s , float dt , int nr_threads , int nr_queues , int nr_nodes , int nodeID , int policy );
127
void engine_prepare ( struct engine *e );
128
129
void engine_step ( struct engine *e );
void engine_maketasks ( struct engine *e );
130
void engine_split ( struct engine *e , int *grid );
131
int engine_exchange_strays ( struct engine *e , int offset , int *ind , int N );
132
133
134
void engine_rebuild ( struct engine *e );
void engine_repartition ( struct engine *e );
void engine_makeproxies ( struct engine *e );
135
void engine_redistribute ( struct engine *e );
136
struct link *engine_addlink( struct engine *e , struct link *l , struct task *t );