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
adcfb495
Commit
adcfb495
authored
May 18, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim ass4 taddeus: Added sequential vibrating string program (untested).
parent
8ca8c52e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
39 deletions
+79
-39
modsim/ass4_taddeus/ring/Makefile
modsim/ass4_taddeus/ring/Makefile
+1
-1
modsim/ass4_taddeus/vibstring/.gitignore
modsim/ass4_taddeus/vibstring/.gitignore
+1
-0
modsim/ass4_taddeus/vibstring/Makefile
modsim/ass4_taddeus/vibstring/Makefile
+5
-4
modsim/ass4_taddeus/vibstring/seq.c
modsim/ass4_taddeus/vibstring/seq.c
+72
-34
No files found.
modsim/ass4_taddeus/ring/Makefile
View file @
adcfb495
CC
=
mpicc
CC
=
mpicc
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-O
2
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-O
0
all
:
test ring
all
:
test ring
test
:
ring_test.o
test
:
ring_test.o
...
...
modsim/ass4_taddeus/vibstring/.gitignore
0 → 100644
View file @
adcfb495
seq
modsim/ass4_taddeus/vibstring/Makefile
View file @
adcfb495
CC
=
mpicc
CC
=
gcc
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-O2
CFLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c99
-O0
-D_GNU_SOURCE
LDFLAGS
=
-lm
all
:
vibstring
all
:
seq
vibstring
:
main
.o
seq
:
seq
.o
clean
:
clean
:
rm
-vf
*
.o vibstring
rm
-vf
*
.o vibstring
modsim/ass4_taddeus/vibstring/seq.c
View file @
adcfb495
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
//
#define DEBUG
#define DEBUG
#define LOOP 100
/*
#define STRIDE 10000
*
#define REPEAT 7
*/
double
**
init_sinus
(
double
l
,
double
dx
,
double
n
,
int
*
steps
)
{
double
**
y
;
int
i
;
*
steps
=
(
int
)
ceil
(
l
/
dx
);
y
=
(
double
**
)
malloc
(
3
*
*
steps
*
sizeof
(
double
));
const
int
data_size
=
LOOP
*
STRIDE
;
for
(
i
=
0
;
i
<
*
steps
;
i
++
)
y
[
i
][
0
]
=
sin
(
n
*
M_PI
*
i
*
dx
/
l
);
return
y
;
}
/*
/*
*
The master task measures the time between the sending and receiving of data.
*
*/
*/
void
(
int
tasks
,
int
rank
)
{
double
**
init_plucked
(
double
l
,
double
dx
,
double
xp
,
int
*
steps
)
{
double
*
data
=
malloc
(
data_size
*
sizeof
(
double
));
double
**
y
,
x
;
MPI_Status
status
;
int
i
;
int
size
,
measurement
,
source
=
(
rank
-
1
+
tasks
)
%
tasks
,
target
=
(
rank
+
1
)
%
tasks
;
*
steps
=
(
int
)
ceil
(
l
/
dx
);
y
=
(
double
**
)
malloc
(
3
*
*
steps
*
sizeof
(
double
));
// Increase the message length with a fixed STRIDE
for
(
size
=
STRIDE
;
size
<=
data_size
;
size
+=
STRIDE
)
{
for
(
i
=
0
;
i
<
*
steps
;
i
++
)
{
// Repeat the measurement
x
=
i
*
dx
;
for
(
measurement
=
1
;
measurement
<=
REPEAT
;
measurement
++
)
{
y
[
i
][
0
]
=
x
<
xp
?
x
/
xp
:
(
l
-
x
)
/
(
l
-
xp
);
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
);
// The string is attached at both ends
y
[
0
][
2
]
=
y
[
0
][
1
]
=
y
[
0
][
0
];
y
[
*
steps
-
1
][
2
]
=
y
[
*
steps
-
1
][
1
]
=
y
[
*
steps
-
1
][
0
];
return
y
;
}
void
iterate
(
double
**
y
,
int
steps
,
double
dx
,
double
T
)
{
double
x
;
int
i
,
prev
=
0
,
current
=
1
,
next
=
2
;
// 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
=
2
;
i
<
steps
;
i
++
)
{
x
=
i
*
dx
;
y
[
i
][
1
]
=
y
[
i
][
0
]
+
.
5
*
T
*
T
*
(
y
[
i
-
1
][
0
]
-
2
*
y
[
i
][
0
]
+
y
[
i
-
1
][
0
]);
}
}
// Iterate over the length of the string
for
(
i
=
1
;
i
<
steps
-
1
;
i
++
)
{
y
[
i
][
next
]
=
2
*
y
[
i
][
current
]
-
y
[
i
][
prev
]
+
T
*
T
*
(
y
[
i
-
1
][
current
]
-
2
*
y
[
i
][
current
]
+
y
[
i
+
1
][
current
]);
prev
=
current
;
current
=
next
;
next
=
(
next
+
1
)
%
3
;
}
}
free
(
data
);
free
(
y
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
const
char
**
argv
)
{
int
tasks
,
rank
,
error
;
int
steps
;
double
**
(
*
method
)(
double
,
double
,
double
,
int
*
);
if
(
(
error
=
MPI_Init
(
&
argc
,
&
argv
))
!=
MPI_SUCCESS
)
{
if
(
argc
<
5
)
{
printf
(
"MPI_init failed (error %d)
\n
"
,
error
);
printf
(
"Usage: %s INIT_METHOD L DX T N|XP
\n
"
,
argv
[
0
]);
MPI_Abort
(
MPI_COMM_WORLD
,
error
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
tasks
);
if
(
!
strcmp
(
argv
[
1
],
"sinus"
)
)
{
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
method
=
init_sinus
;
}
else
if
(
!
strcmp
(
argv
[
1
],
"plucked"
)
)
{
if
(
!
rank
)
method
=
init_plucked
;
master
(
tasks
);
}
else
{
else
printf
(
"Unknown method '%s'.
\n
"
,
argv
[
1
]);
slave
(
tasks
,
rank
);
return
EXIT_FAILURE
;
}
MPI_Finalize
();
iterate
((
*
method
)(
atof
(
argv
[
2
]),
atof
(
argv
[
3
]),
atof
(
argv
[
5
]),
&
steps
),
steps
,
atof
(
argv
[
3
]),
atof
(
argv
[
4
]));
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
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