1 #ifndef _NBODY_MTHREAD_H
2 #define _NBODY_MTHREAD_H
5 #include "../single-thread/nbody.h" //Use original simulation code
11 #define DEFAULT_WORKING_THREADS 2
13 #define PERSISTENT_THREADS //If defined, threads will not be continually destroyed and then respawned
15 //Undefine default macros, replace with functions
17 void Simulation_Run(int argc, char ** argv);
19 void QuitProgram(bool error);
27 void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
29 void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system
30 void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system
34 void Thread_Cleanup(void); //Called at program exit to safely join computation thread
38 pthread_mutex_t mutex;
39 unsigned threads_busy; // Counter of threads which are busy
40 pthread_cond_t threads_done_cv;
43 void Barrier_Init(Barrier * b);
44 void Barrier_Enter(Barrier * b);
45 void Barrier_Leave(Barrier * b);
46 void Barrier_Wait(Barrier * b);
48 #endif //_NBODY_MTHREAD_H