Parallel Programming - Work on pthreaded version
[matches/honours.git] / course / semester2 / pprog / assignment1 / mthread / nbody.h
diff --git a/course/semester2/pprog/assignment1/mthread/nbody.h b/course/semester2/pprog/assignment1/mthread/nbody.h
new file mode 100644 (file)
index 0000000..80bfb82
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef _NBODY_H
+#define _NBODY_H
+
+/**
+ * @file nbody.h
+ * @author Sam Moore (205030628)
+ * @purpose N-Body simulator: declarations of simulation related parameters
+ */
+
+#define NUM_THREADS 4
+
+#include <pthread.h>
+#include <stdbool.h>
+
+#define M_PI        3.14159265358979323846264338327950288   /* pi */
+#define G 6.67428E-11
+#define DELTA_T 0.05
+#define DIMENSIONS 3
+#define square(x) ((x)*(x))
+
+
+/**
+ * Structure to represent a single Body
+ * @param mass - Mass of the body
+ * @param x - Position vector (array)
+ * @param v - Velocity vector (array)
+ * @param F - Net force vector (array)
+ */
+typedef struct 
+{
+
+       double mass;
+       double x[DIMENSIONS];
+       double v[DIMENSIONS];
+       double F[DIMENSIONS];
+
+} Body;
+
+/**
+ * Structure to store an array of bodies, along with the size of the array.
+ * The universe is represented in a single System. 
+ * @param N - Size of the array
+ * @param body - The array of bodies
+ */
+typedef struct
+{
+       unsigned N;
+       Body * body;
+
+} System;
+
+void Body_Print(Body * a); //Print body a
+void Body_Force(Body * a, System * s); //Compute force on body a due to system of bodies s
+void Body_Velocity(Body * a); //Compute velocity of body a
+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 Universe_Cleanup();
+
+extern System universe; // The main array of bodies; global variable.
+
+
+/**
+ * Multithreading stuff below here
+ */
+
+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
+
+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