Parallel Programming - Start OpenMP Version
[matches/honours.git] / course / semester2 / pprog / assignment1 / mthread / nbody.h
1 #ifndef _NBODY_MTHREAD_H
2 #define _NBODY_MTHREAD_H
3
4
5 #include "../single-thread/nbody.h" //Use original simulation code
6 #include <pthread.h>
7
8 #undef SINGLE_THREADED
9 #define PTHREADED
10
11 #define DEFAULT_WORKING_THREADS 2 
12
13 //Undefine default macros, replace with functions
14 #undef Simulation_Run
15 void Simulation_Run(int argc, char ** argv);
16 #undef QuitProgram
17 void QuitProgram(bool error);
18
19
20 void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
21
22 void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system
23 void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system
24
25
26
27 void Thread_Cleanup(void); //Called at program exit to safely join computation thread
28
29 extern pthread_t compute_thread; // ID of the thread that runs Compute_Thread. 
30 extern pthread_mutex_t mutex_runstate; //Mutex around the "runstate" variable
31
32 extern pthread_t * worker_thread; //Array of worker threads responsible for Force and Position updates
33 extern System * sub_system; //Array of Systems used to divide up the main "universe" System for worker threads
34 extern pthread_mutex_t mutex_workers;
35 extern pthread_cond_t workers_done_cv;
36 extern unsigned workers_busy;
37
38 #endif //_NBODY_MTHREAD_H

UCC git Repository :: git.ucc.asn.au