Parallel Programming - Commit before I break everything
[matches/honours.git] / course / semester2 / pprog / assignment1 / mthread / nbody.h
index 7abe525..f2de022 100644 (file)
@@ -10,7 +10,7 @@
 
 #define DEFAULT_WORKING_THREADS 2 
 
-//#define PERSISTENT_THREADS //If defined, threads will not be continually destroyed and then respawned
+#define PERSISTENT_THREADS //If defined, threads will not be continually destroyed and then respawned
 
 
 
@@ -28,15 +28,24 @@ void AfterDraw();
 
 void * Compute_Thread(void * system); //Thread - Continuously perform computations for a System of bodies. May spawn additional worker threads.
 
+
+System * Split_System(System * s, unsigned n); // Splits one system into a number of other systems, returns an array of size n
+pthread_t * Allocate_Threads(unsigned n); // Allocates space for threads - handles errors
+
 #ifdef PERSISTENT_THREADS
 void * Worker_Thread(void * arg);
-#else
+#endif //PERSISTENT_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
-#endif //PERSISTENT_THREADS
 
 void Thread_Cleanup(void); //Called at program exit to safely join computation thread
 
+/**
+ * Structure to represent a barrier for multiple threads
+ * @param mutex - Mutex around the counter
+ * @param busy - Counter of threads within the barrier
+ * @param threads_done_cv - Condition to wake up threads waiting on barrier once all working threads have left it
+ */
 typedef struct
 {
        pthread_mutex_t mutex;
@@ -44,6 +53,17 @@ typedef struct
        pthread_cond_t threads_done_cv;
 } Barrier;
 
+/**
+ * Structure to represent a pair of Systems; passed to Force_Thread
+ * @param A - System to calculate forces for
+ * @param B - System causing forces on System A
+ */
+typedef struct
+{
+       System * A;
+       System * B;
+} System_ForcePair;
+
 void Barrier_Init(Barrier * b);
 void Barrier_Enter(Barrier * b);
 void Barrier_Leave(Barrier * b);

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