Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
7f895397
Commit
7f895397
authored
Jul 08, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim ass4 taddeus: Fixed MPI implementation (finally...).
parent
09b18960
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
23 deletions
+21
-23
modsim/ass4_taddeus/vibstring/par.c
modsim/ass4_taddeus/vibstring/par.c
+20
-22
modsim/ass4_taddeus/vibstring/par.sh
modsim/ass4_taddeus/vibstring/par.sh
+1
-1
No files found.
modsim/ass4_taddeus/vibstring/par.c
View file @
7f895397
...
...
@@ -14,19 +14,18 @@ FILE *file;
* receiving the outer borders calculated by the adjacent nodes
*/
void
interact
(
int
state
)
{
int
prev
=
(
rank
-
1
+
tasks
)
%
tasks
,
next
=
(
rank
+
1
)
%
tasks
;
MPI_Status
status
;
// Left border
if
(
rank
)
{
MPI_Sendrecv
(
y
[
state
]
+
1
,
1
,
MPI_DOUBLE
,
prev
,
0
,
y
[
state
],
1
,
MPI_DOUBLE
,
prev
,
MPI_ANY_TAG
,
MPI_COMM_WORLD
,
&
status
);
MPI_Sendrecv
(
y
[
state
]
+
1
,
1
,
MPI_DOUBLE
,
rank
-
1
,
0
,
y
[
state
],
1
,
MPI_DOUBLE
,
rank
-
1
,
MPI_ANY_TAG
,
MPI_COMM_WORLD
,
&
status
);
}
// Right border
if
(
rank
<
tasks
-
1
)
{
MPI_Sendrecv
(
y
[
state
]
+
steps
,
1
,
MPI_DOUBLE
,
next
,
0
,
y
[
state
]
+
steps
+
1
,
1
,
MPI_DOUBLE
,
next
,
MPI_ANY_TAG
,
MPI_Sendrecv
(
y
[
state
]
+
steps
,
1
,
MPI_DOUBLE
,
rank
+
1
,
0
,
y
[
state
]
+
steps
+
1
,
1
,
MPI_DOUBLE
,
rank
+
1
,
MPI_ANY_TAG
,
MPI_COMM_WORLD
,
&
status
);
}
}
...
...
@@ -38,17 +37,14 @@ void init_borders() {
else
if
(
rank
==
tasks
-
1
)
y
[
2
][
steps
]
=
y
[
1
][
steps
]
=
y
[
0
][
steps
];
//
interact(0);
interact
(
0
);
}
/*
* Fill the assigned string section with a sinus shape
*/
void
init_sinus
(
double
l
,
double
dx
,
double
n
)
{
int
i
;
printf
(
"start: %d
\n
"
,
start
);
for
(
i
=
0
;
i
<
steps
;
i
++
)
for
(
int
i
=
0
;
i
<
steps
;
i
++
)
y
[
0
][
i
+
1
]
=
sin
(
n
*
M_PI
*
(
i
+
start
)
*
dx
/
l
);
init_borders
();
...
...
@@ -59,9 +55,8 @@ void init_sinus(double l, double dx, double n) {
*/
void
init_plucked
(
double
l
,
double
dx
,
double
xp
)
{
double
x
;
int
i
;
for
(
i
=
0
;
i
<
steps
;
i
++
)
{
for
(
i
nt
i
=
0
;
i
<
steps
;
i
++
)
{
x
=
(
i
+
start
)
*
dx
;
y
[
0
][
i
+
1
]
=
x
<
xp
?
x
/
xp
:
(
l
-
x
)
/
(
l
-
xp
);
}
...
...
@@ -75,8 +70,8 @@ void init_plucked(double l, double dx, double xp) {
#define PRINT_FORMAT "%e"
void
print
(
int
index
)
{
for
(
int
i
=
0
;
i
<
steps
;
i
++
)
{
if
(
i
)
for
(
int
i
=
1
;
i
<=
steps
;
i
++
)
{
if
(
i
>
1
)
fprintf
(
file
,
" "
);
fprintf
(
file
,
PRINT_FORMAT
,
y
[
index
][
i
]);
...
...
@@ -91,16 +86,19 @@ void print(int index) {
*/
void
calculate_steps
(
int
time
,
double
dx
,
double
tau
)
{
double
x
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
;
int
i
,
t
,
prev
=
0
,
current
=
1
,
next
=
2
,
s
=
rank
?
1
:
2
,
e
=
rank
==
tasks
-
1
?
steps
-
1
:
steps
;
// 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)
for
(
i
=
1
;
i
<=
steps
;
i
++
)
{
for
(
i
=
s
;
i
<=
e
;
i
++
)
{
x
=
i
*
dx
;
y
[
1
][
i
]
=
y
[
0
][
i
]
+
.
5
*
tau
*
tau
*
(
y
[
0
][
i
-
1
]
-
2
*
y
[
0
][
i
]
+
y
[
0
][
i
+
1
]);
y
[
current
][
i
]
=
y
[
0
][
i
]
+
.
5
*
tau
*
tau
*
(
y
[
0
][
i
-
1
]
-
2
*
y
[
0
][
i
]
+
y
[
0
][
i
+
1
]);
}
interact
(
current
);
#ifdef VERBOSE
// Print x values (which are the same for every y-series)
for
(
i
=
0
;
i
<
steps
;
i
++
)
{
...
...
@@ -119,11 +117,13 @@ void calculate_steps(int time, double dx, double tau) {
// Iterate over the length of the string for each time interval step
for
(
t
=
2
;
t
<
time
;
t
++
)
{
for
(
i
=
1
;
i
<=
steps
;
i
++
)
{
for
(
i
=
s
;
i
<=
e
;
i
++
)
{
y
[
next
][
i
]
=
2
*
y
[
current
][
i
]
-
y
[
prev
][
i
]
+
tau
*
tau
*
(
y
[
current
][
i
-
1
]
-
2
*
y
[
current
][
i
]
+
y
[
current
][
i
+
1
]);
}
interact
(
next
);
#ifdef VERBOSE
print
(
next
);
#endif
...
...
@@ -131,8 +131,6 @@ void calculate_steps(int time, double dx, double tau) {
prev
=
current
;
current
=
next
;
next
=
(
next
+
1
)
%
3
;
interact
(
next
);
}
}
...
...
@@ -187,7 +185,7 @@ int main(int argc, char **argv) {
// allocate the left and right outer border values that are calculated by
// other nodes
if
(
rank
==
tasks
-
1
)
steps
+=
total_steps
-
steps
*
(
tasks
-
1
)
;
steps
+=
total_steps
%
steps
;
// Allocate a 3xN two-dimensional area for this part of the string that
// functions as a cyclic buffer for three states of the string (previous,
...
...
modsim/ass4_taddeus/vibstring/par.sh
View file @
7f895397
...
...
@@ -6,7 +6,7 @@ PROGRAM_EXEC=./par
ARGS
=
sinus 1001 1 .01 1 1
#mpirun -np $NUM_PROCESSES ./par sinus 100 1 .01 1 1
mpirun
-np
$NUM_PROCESSES
./par sinus
3
1 .01 1 1
mpirun
-np
$NUM_PROCESSES
./par sinus
50
1 .01 1 1
#mpirun -np $NUM_PROCESSES $PROGRAM_EXEC $ARGS
#mpirun -np $NUM_PROCESSES --mca pls_rsh_agent $RSH_AGENT \
# --hostfile $MPI_HOSTFILE $PROGRAM_EXEC
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment