Commit 253c9703 authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass4 taddeus: Added 1 x-step for better drawing results.

parent bdc22082
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <mpi.h> #include <mpi.h>
#include <assert.h> #include <assert.h>
#define VERBOSE
double **y = NULL; double **y = NULL;
int tasks, rank, steps, start; int tasks, rank, steps, start;
FILE *file; FILE *file;
...@@ -64,8 +66,6 @@ void init_plucked(double l, double dx, double xp) { ...@@ -64,8 +66,6 @@ void init_plucked(double l, double dx, double xp) {
init_borders(); init_borders();
} }
#define VERBOSE
#ifdef VERBOSE #ifdef VERBOSE
#define PRINT_FORMAT "%e" #define PRINT_FORMAT "%e"
...@@ -177,7 +177,7 @@ int main(int argc, char **argv) { ...@@ -177,7 +177,7 @@ int main(int argc, char **argv) {
file = fopen(filename, "w"); file = fopen(filename, "w");
// Calculate the indices of the string to calculate // Calculate the indices of the string to calculate
total_steps = (int)ceil(l / dx); total_steps = (int)ceil(l / dx) + 1;
steps = total_steps / tasks; steps = total_steps / tasks;
start = steps * rank; start = steps * rank;
......
#!/bin/bash #!/bin/bash
if [ $# -lt 7 ]; then
echo "Usage: $0 NUM_PROCESSES INIT_METHOD TIME_STEPS LENGTH DX TAU N|XP"
exit 1
fi
mpirun -np ${1-4} ./par ${@:2:$#} mpirun -np ${1-4} ./par ${@:2:$#}
#mpirun -np ${1-4} ./par sinus 100 1 .01 1 1 #mpirun -np ${1-4} ./par sinus 100 1 .01 1 1
#mpirun -np ${1-4} --mca pls_rsh_agent rsa \ #mpirun -np ${1-4} --mca pls_rsh_agent rsa \
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
\section{Inleiding} \section{Inleiding}
Het tweede deel van practicumopdracht 4 omhelst het programmeren van een
\section{Theorie} \section{Theorie}
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#define VERBOSE
double **y = NULL, dx; double **y = NULL, dx;
int steps, time; int steps, time;
...@@ -34,8 +36,6 @@ void init_plucked(double l, double xp) { ...@@ -34,8 +36,6 @@ void init_plucked(double l, double xp) {
y[2][steps - 1] = y[1][steps - 1] = y[0][steps - 1]; y[2][steps - 1] = y[1][steps - 1] = y[0][steps - 1];
} }
#define VERBOSE
#ifdef VERBOSE #ifdef VERBOSE
#define PRINT_FORMAT "%e" #define PRINT_FORMAT "%e"
...@@ -62,8 +62,8 @@ void calculate_steps(int time, double tau) { ...@@ -62,8 +62,8 @@ void calculate_steps(int time, double tau) {
// position at t = 0 and the information that y(x, -dt) == y(x, dt) // position at t = 0 and the information that y(x, -dt) == y(x, dt)
for( i = 1; i < steps - 1; i++ ) { for( i = 1; i < steps - 1; i++ ) {
x = i * dx; x = i * dx;
y[1][i] = y[0][i] + .5 * tau * tau * (y[0][i-1] - 2 * y[0][i] y[1][i] = y[0][i] + .5 * tau * tau * (y[0][i - 1] - 2 * y[0][i]
+ y[0][i+1]); + y[0][i + 1]);
} }
#ifdef VERBOSE #ifdef VERBOSE
...@@ -86,7 +86,7 @@ void calculate_steps(int time, double tau) { ...@@ -86,7 +86,7 @@ void calculate_steps(int time, double tau) {
for( t = 2; t < time; t++ ) { for( t = 2; t < time; t++ ) {
for( i = 1; i < steps - 1; i++ ) { for( i = 1; i < steps - 1; i++ ) {
y[next][i] = 2 * y[current][i] - y[prev][i] + tau * tau y[next][i] = 2 * y[current][i] - y[prev][i] + tau * tau
* (y[current][i-1] - 2 * y[current][i] + y[current][i+1]); * (y[current][i - 1] - 2 * y[current][i] + y[current][i + 1]);
} }
#ifdef VERBOSE #ifdef VERBOSE
...@@ -126,14 +126,11 @@ int main(int argc, const char **argv) { ...@@ -126,14 +126,11 @@ int main(int argc, const char **argv) {
tau = atof(argv[5]); tau = atof(argv[5]);
constant = atof(argv[6]); constant = atof(argv[6]);
// Allocate a 3xN two-dimensional area that functions as a cyclic buffer // Allocate a 3xN two-dimensional area that acts as a cyclic buffer for
// for three states of the string (previous, current, next) // three states of the string (previous, current, next)
steps = (int)ceil(l / dx); steps = (int)ceil(l / dx) + 1;
if( (y = (double **)malloc(3 * sizeof(double *))) == NULL ) { y = (double **)malloc(3 * sizeof(double *));
puts("Error: could not allocate memory.");
exit(EXIT_FAILURE);
}
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
y[i] = (double *)malloc(steps * sizeof(double)); y[i] = (double *)malloc(steps * sizeof(double));
......
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