Commit ff0f13b4 authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass4 taddeus: Added shell script for mpi.

parent b545fb9b
...@@ -75,13 +75,16 @@ void init_plucked(double l, double xp) { ...@@ -75,13 +75,16 @@ void init_plucked(double l, double xp) {
void print(int index) { void print(int index) {
for( int i = 0; i < steps; i++ ) { for( int i = 0; i < steps; i++ ) {
if( i ) if( i || rank )
printf(" "); printf(" ");
printf(PRINT_FORMAT, y[index][i]); printf(PRINT_FORMAT, y[index][i]);
} }
puts(""); if( last_node() )
puts("");
fflush(stdout);
} }
#endif #endif
...@@ -94,7 +97,7 @@ void calculate_steps(int time, double tau) { ...@@ -94,7 +97,7 @@ void calculate_steps(int time, double tau) {
// Calculate the position over the entire string at time dt using the // Calculate the position over the entire string at time dt using the
// 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; 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]);
...@@ -106,10 +109,11 @@ void calculate_steps(int time, double tau) { ...@@ -106,10 +109,11 @@ void calculate_steps(int time, double tau) {
if( i ) if( i )
printf(" "); printf(" ");
printf(PRINT_FORMAT, i * dx); printf(PRINT_FORMAT, (i + start) * dx);
} }
puts(""); puts("");
fflush(stdout);
// Print init states // Print init states
print(prev); print(prev);
...@@ -118,7 +122,7 @@ void calculate_steps(int time, double tau) { ...@@ -118,7 +122,7 @@ void calculate_steps(int time, double tau) {
// Iterate over the length of the string for each time interval step // Iterate over the length of the string for each time interval step
for( t = 2; t < time; t++ ) { for( t = 2; t < time; t++ ) {
for( i = 1; i < steps - 1; i++ ) { for( i = 1; i <= steps; 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]);
} }
...@@ -130,6 +134,8 @@ void calculate_steps(int time, double tau) { ...@@ -130,6 +134,8 @@ void calculate_steps(int time, double tau) {
prev = current; prev = current;
current = next; current = next;
next = (next + 1) % 3; next = (next + 1) % 3;
connect(next);
} }
} }
...@@ -201,7 +207,7 @@ int main(int argc, char **argv) { ...@@ -201,7 +207,7 @@ int main(int argc, char **argv) {
free(y); free(y);
// Finalize mPI // Finalize MPI
MPI_Finalize(); MPI_Finalize();
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
#!/bin/sh
NUM_PROCESSES=${1-4} # Default: 4 processes
#RSH_AGENT=rsh
#MPI_HOSTFILE=~/.mpirun.machines
PROGRAM_EXEC=par
ARGS=sinus 1001 1 .01 1 1
mpirun -np $NUM_PROCESSES $PROGRAM_EXEC
#mpirun -np $NUM_PROCESSES --mca pls_rsh_agent $RSH_AGENT \
# --hostfile $MPI_HOSTFILE $PROGRAM_EXEC
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