Commit 8ca8c52e authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass4 taddeus: Added files for sequential vibrating string.

parent 7cf913bd
......@@ -22,7 +22,7 @@ void master(int tasks) {
// generate data to send
for( i = 0; i < data_size; i++ )
sent[i] = .0;
sent[i] = (float)i;
// Increase the message length with a fixed STRIDE
for( size = STRIDE; size <= data_size; size += STRIDE ) {
......
CC=mpicc
CFLAGS=-Wall -Wextra -pedantic -std=c99 -O2
all: vibstring
vibstring: main.o
clean:
rm -vf *.o vibstring
#include <stdlib.h>
#include <stdio.h>
//#define DEBUG
#define LOOP 100
#define STRIDE 10000
#define REPEAT 7
const int data_size = LOOP * STRIDE;
/*
* The master task measures the time between the sending and receiving of data.
*/
void (int tasks, int rank) {
double *data = malloc(data_size * sizeof(double));
MPI_Status status;
int size, measurement,
source = (rank - 1 + tasks) % tasks, target = (rank + 1) % tasks;
// Increase the message length with a fixed STRIDE
for( size = STRIDE; size <= data_size; size += STRIDE ) {
// Repeat the measurement
for( measurement = 1; measurement <= REPEAT; measurement++ ) {
MPI_Recv(data, size, MPI_DOUBLE, source, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
MPI_Send(data, size, MPI_DOUBLE, target, 0, MPI_COMM_WORLD);
}
}
free(data);
}
int main(int argc, char **argv) {
int tasks, rank, error;
if( (error = MPI_Init(&argc, &argv)) != MPI_SUCCESS ) {
printf("MPI_init failed (error %d)\n", error);
MPI_Abort(MPI_COMM_WORLD, error);
return EXIT_FAILURE;
}
MPI_Comm_size(MPI_COMM_WORLD, &tasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if( !rank )
master(tasks);
else
slave(tasks, rank);
MPI_Finalize();
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