Parallel Programming - Finished(?) pthread version
[matches/honours.git] / course / semester2 / pprog / assignment1 / mthread / nbody.h
index 80bfb82..b9cac6f 100644 (file)
@@ -7,7 +7,10 @@
  * @purpose N-Body simulator: declarations of simulation related parameters
  */
 
-#define NUM_THREADS 4
+
+#define NUM_THREADS 5 //The number of *worker* threads (not including the computation thread) to use. 
+                       // If this is 1, the computation thread will not spawn any workers (faster to just do the work itself), 
+                       //      otherwise it will spawn NUM_THREADS workers.
 
 #include <pthread.h>
 #include <stdbool.h>
@@ -56,7 +59,8 @@ void Body_Position(Body * a); //Compute position of body a
 
 void System_Init(System * s, char * fileName); //Initialise System (array of bodies) from a text file
 
-void System_Compute(System * system); //Perform a single computation step for a System of bodies
+void System_Forces(System * s1, System * s2); //Compute forces for bodies in s1 due to bodies in s2 (also updates velocities)
+void System_Positions(System * s); //Update positions for bodies in s1
 void Universe_Cleanup();
 
 extern System universe; // The main array of bodies; global variable.
@@ -67,10 +71,17 @@ extern System universe; // The main array of bodies; global variable.
  */
 
 extern pthread_t compute_thread; // ID of the thread that runs Compute_Thread. Set in main()
-void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies
+void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
+
+void * Force_Thread(void * system); //Thread - Compute forces for all objects in a system
+void * Position_Thread(void * system); //Thread - Compute positions for all objects in a system
+
+typedef enum {RUN, QUIT, QUIT_ERROR} RUNSTATE;
+extern RUNSTATE runstate;
+extern pthread_mutex_t mutex_runstate; //Mutex around the "runstate" variable
+
+void QuitProgram(bool error);
 
-extern bool terminate; //Will be set to true by main thread to signal children to terminate. Child threads are responsible for checking.
-extern pthread_mutex_t mutex_terminate; //Mutex around the "terminate" variable
 
 
 #endif //_NBODY_H

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