6 * @author Sam Moore (205030628)
7 * @purpose N-Body simulator: declarations of simulation related parameters
11 #define NUM_THREADS 5 //The number of *worker* threads (not including the computation thread) to use.
12 // If this is 1, the computation thread will not spawn any workers (faster to just do the work itself),
13 // otherwise it will spawn NUM_THREADS workers.
18 #define M_PI 3.14159265358979323846264338327950288 /* pi */
22 #define square(x) ((x)*(x))
26 * Structure to represent a single Body
27 * @param mass - Mass of the body
28 * @param x - Position vector (array)
29 * @param v - Velocity vector (array)
30 * @param F - Net force vector (array)
43 * Structure to store an array of bodies, along with the size of the array.
44 * The universe is represented in a single System.
45 * @param N - Size of the array
46 * @param body - The array of bodies
55 void Body_Print(Body * a); //Print body a
56 void Body_Force(Body * a, System * s); //Compute force on body a due to system of bodies s
57 void Body_Velocity(Body * a); //Compute velocity of body a
58 void Body_Position(Body * a); //Compute position of body a
60 void System_Init(System * s, char * fileName); //Initialise System (array of bodies) from a text file
62 void System_Forces(System * s1, System * s2); //Compute forces for bodies in s1 due to bodies in s2 (also updates velocities)
63 void System_Positions(System * s); //Update positions for bodies in s1
64 void Universe_Cleanup();
66 extern System universe; // The main array of bodies; global variable.
70 * Multithreading stuff below here
73 extern pthread_t compute_thread; // ID of the thread that runs Compute_Thread. Set in main()
74 void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
76 void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system
77 void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system
79 typedef enum {RUN, QUIT, QUIT_ERROR} RUNSTATE;
80 extern RUNSTATE runstate;
81 extern pthread_mutex_t mutex_runstate; //Mutex around the "runstate" variable
83 void QuitProgram(bool error);