Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
7f895397
Commit
7f895397
authored
13 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
ModSim ass4 taddeus: Fixed MPI implementation (finally...).
parent
09b18960
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modsim/ass4_taddeus/vibstring/par.c
+20
-22
20 additions, 22 deletions
modsim/ass4_taddeus/vibstring/par.c
modsim/ass4_taddeus/vibstring/par.sh
+1
-1
1 addition, 1 deletion
modsim/ass4_taddeus/vibstring/par.sh
with
21 additions
and
23 deletions
modsim/ass4_taddeus/vibstring/par.c
+
20
−
22
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
(
int
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,
...
...
This diff is collapsed.
Click to expand it.
modsim/ass4_taddeus/vibstring/par.sh
+
1
−
1
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment