Commit 721be58d authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass4 taddeus: Source code cleanup.

parent 965539d0
...@@ -4,14 +4,15 @@ ...@@ -4,14 +4,15 @@
//#define DEBUG //#define DEBUG
#define LOOP 100 #define LOOP 100 // Number of different message sizes
#define STRIDE 10000 #define STRIDE 10000 // Difference between the message sizes
#define REPEAT 7 #define REPEAT 7 // Number of times to repeat a measurement
const int data_size = LOOP * STRIDE; const int data_size = LOOP * STRIDE;
/* /*
* The master task measures the time between the sending and receiving of data. * The master task initiates the transport of data and waits for it to come
* back. The time between sending and receiving is measured and printed.
*/ */
void master(int tasks) { void master(int tasks) {
double *received = malloc(data_size * sizeof(double)), double *received = malloc(data_size * sizeof(double)),
...@@ -22,7 +23,7 @@ void master(int tasks) { ...@@ -22,7 +23,7 @@ void master(int tasks) {
// generate data to send // generate data to send
for( i = 0; i < data_size; i++ ) for( i = 0; i < data_size; i++ )
sent[i] = (float)i; sent[i] = (double)i;
// Increase the message length with a fixed STRIDE // Increase the message length with a fixed STRIDE
for( size = STRIDE; size <= data_size; size += STRIDE ) { for( size = STRIDE; size <= data_size; size += STRIDE ) {
...@@ -89,6 +90,7 @@ void slave(int tasks, int rank) { ...@@ -89,6 +90,7 @@ void slave(int tasks, int rank) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int tasks, rank, error; int tasks, rank, error;
// Initialize adnd setup MPI
if( (error = MPI_Init(&argc, &argv)) != MPI_SUCCESS ) { if( (error = MPI_Init(&argc, &argv)) != MPI_SUCCESS ) {
printf("MPI_init failed (error %d)\n", error); printf("MPI_init failed (error %d)\n", error);
MPI_Abort(MPI_COMM_WORLD, error); MPI_Abort(MPI_COMM_WORLD, error);
...@@ -98,11 +100,13 @@ int main(int argc, char **argv) { ...@@ -98,11 +100,13 @@ int main(int argc, char **argv) {
MPI_Comm_size(MPI_COMM_WORLD, &tasks); MPI_Comm_size(MPI_COMM_WORLD, &tasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Execute the measurements
if( !rank ) if( !rank )
master(tasks); master(tasks);
else else
slave(tasks, rank); slave(tasks, rank);
// Finalize mPI
MPI_Finalize(); MPI_Finalize();
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment