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
62d0f0a8
Commit
62d0f0a8
authored
Jul 10, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ModSim ass4 part 1 and 2 are not finished.
parent
dd69ac78
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
46 deletions
+93
-46
modsim/ass4_sander/part1/start.sh
modsim/ass4_sander/part1/start.sh
+1
-1
modsim/ass4_sander/part2/Makefile
modsim/ass4_sander/part2/Makefile
+1
-1
modsim/ass4_sander/part2/main.c
modsim/ass4_sander/part2/main.c
+79
-43
modsim/ass4_sander/part2/plot.py
modsim/ass4_sander/part2/plot.py
+12
-1
No files found.
modsim/ass4_sander/part1/start.sh
View file @
62d0f0a8
#!/bin/sh
#!/bin/sh
NUM_PROCESSES
=
4
NUM_PROCESSES
=
4
HOSTS
=
ow130,ow131
HOSTS
=
deleuze,localhost
PROGRAM_EXEC
=
main
PROGRAM_EXEC
=
main
mpirun
-np
$NUM_PROCESSES
-H
$HOSTS
$PROGRAM_EXEC
mpirun
-np
$NUM_PROCESSES
-H
$HOSTS
$PROGRAM_EXEC
modsim/ass4_sander/part2/Makefile
View file @
62d0f0a8
CFLAGS
+=
-std
=
c99
-Wall
-Wextra
-
g
-O2
-pthread
CFLAGS
+=
-std
=
c99
-Wall
-Wextra
-
pedantic
-g
-O2
-pthread
-D_GNU_SOURCE
LDFLAGS
+=
-pthread
-lmpi
-lopen-rte
-lopen-pal
-ldl
-Wl
,--export-dynamic
\
LDFLAGS
+=
-pthread
-lmpi
-lopen-rte
-lopen-pal
-ldl
-Wl
,--export-dynamic
\
-lnsl
-lutil
-lm
-ldl
-lnsl
-lutil
-lm
-ldl
...
...
modsim/ass4_sander/part2/main.c
View file @
62d0f0a8
...
@@ -2,84 +2,120 @@
...
@@ -2,84 +2,120 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#define
GRID_LENGTH 64
#define
STRING_PARTS len
double
Y
[
GRID_LENGTH
][
3
];
int
STRING_PARTS
;
double
*
Y
;
int
t_next
,
t_prev
,
t_cur
;
int
t_next
,
t_prev
,
t_cur
;
void
init_sinus
(
char
**
argv
)
{
/*
double
amp
;
* Macros used to manipulate the allocated memory for Y.
int
h_phases
;
*/
#define GET_Y(i, t) \
Y[i + t * STRING_PARTS]
sscanf
(
argv
[
2
],
"%lf"
,
&
amp
);
#define SET_Y(i, t, val) \
sscanf
(
argv
[
3
],
"%i"
,
&
h_phases
);
Y[i + t * STRING_PARTS] = val
for
(
int
i
=
0
;
i
<
GRID_LENGTH
;
i
++
)
{
Y
[
i
][
t
]
=
amp
*
sin
(
M_PI
*
(
i
(
double
)
/
(
double
)
GRID_LENGTH
)
*
h_phases
);
}
}
void
init_pluck
(
char
**
argv
)
{
/*
double
amp
,
position
;
* Fill the allocated memory for Y with a sinus shape.
int
ipos
,
i
;
*/
static
void
init_sinus
(
int
phases
)
{
double
c
=
(
double
)
(
STRING_PARTS
*
phases
)
*
M_PI
;
sscanf
(
argv
[
2
],
"%lf"
,
&
amp
);
for
(
int
i
=
0
;
i
<
STRING_PARTS
;
i
++
)
{
sscanf
(
argv
[
3
],
"%i"
,
&
position
);
SET_Y
(
i
,
0
,
sin
(((
double
)
i
)
/
c
));
}
}
ipos
=
position
/
dx
*
GRID_LENGTH
;
/*
* Fill the allocated memory for Y with a pluck shape.
*/
static
void
init_pluck
(
double
pluck
,
double
length
,
double
dx
)
{
int
ipos
=
((
int
)
dx
)
+
1
,
i
;
fprintf
(
stderr
,
"ipos: %d
\n
"
,
ipos
);
for
(
i
=
0
;
i
<
ipos
;
i
++
)
{
for
(
i
=
0
;
i
<
ipos
;
i
++
)
{
Y
[
i
][
t
]
=
i
*
dx
/
position
*
amp
;
SET_Y
(
i
,
0
,
i
*
dx
/
pluck
)
;
}
}
for
(;
i
<
GRID_LENGTH
;
i
++
)
{
Y
[
i
][
t
]
=
((
GRID_LENGTH
-
i
)
*
dx
)
/
(
GRID_LENGTH
-
ipos
)
*
amp
;
for
(
;
i
<
STRING_PARTS
;
i
++
)
{
SET_Y
(
i
,
0
,
((
STRING_PARTS
-
i
)
*
dx
)
/
(
STRING_PARTS
-
ipos
));
}
}
}
}
void
iterate
(
double
C
,
int
t_prev
,
int
t_cur
,
int
t_next
)
{
static
void
connect_string_ends
()
{
for
(
int
i
=
1
;
i
<
GRID_LENGTH
;
i
++
)
{
const
int
end
=
STRING_PARTS
-
1
;
Y
[
i
][
t_next
]
=
C
*
(
Y
[
i
-
1
][
t_cur
]
-
2
*
Y
[
i
][
t_cur
]
+
Y
[
i
+
1
][
t_cur
])
Y
[
STRING_PARTS
*
2
]
=
Y
[
STRING_PARTS
*
1
]
=
Y
[
STRING_PARTS
];
-
Y
[
i
][
t_prev
]
Y
[
STRING_PARTS
*
2
+
end
]
=
Y
[
STRING_PARTS
*
1
+
end
]
=
Y
[
STRING_PARTS
+
end
];
+
2
*
Y
[
i
][
t_cur
];
}
/*
* Calculate position over the entire string at time 't_cur' (= dt).
*/
static
void
iterate
(
double
C
,
int
t_prev
,
int
t_cur
,
int
t_next
)
{
for
(
int
i
=
1
,
max
=
STRING_PARTS
-
1
;
i
<
max
;
i
++
)
{
SET_Y
(
i
,
t_next
,
\
C
*
(
GET_Y
(
i
-
1
,
t_cur
)
-
2
*
GET_Y
(
i
,
t_cur
)
+
GET_Y
(
i
+
1
,
t_cur
))
-
GET_Y
(
i
,
t_prev
)
+
2
*
GET_Y
(
i
,
t_cur
));
}
}
}
}
/*
* Integer XOR swapping macro.
*/
#define SWAP(a, b) \
#define SWAP(a, b) \
a ^= b; \
a ^= b; \
b ^= a; \
b ^= a; \
a ^= b;
a ^= b;
static
void
plot
(
int
col
)
{
printf
(
"%e"
,
GET_Y
(
0
,
col
));
for
(
int
i
=
1
;
i
<
STRING_PARTS
;
i
++
)
printf
(
",%e"
,
GET_Y
(
i
,
col
));
void
plot
(
int
col
)
{
printf
(
"%f"
,
Y
[
0
][
col
]);
for
(
int
i
=
1
;
i
<
GRID_LENGTH
;
i
++
)
printf
(
",%f"
,
Y
[
i
][
col
]);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
4
)
{
if
(
argc
<
7
)
{
fprintf
(
stderr
,
"Usage: %s <p amplitude position |s amplitude phases"
,
argv
[
0
]);
fprintf
(
stderr
,
"Usage: %s <p|s> ITERATIONS LENGTH STEP_SIZE"
\
" TAU <PLUCK|PHASES>
\n
"
,
argv
[
0
]);
return
1
;
return
1
;
}
}
// Initialise time indices, iterations and string length.
int
t_prev
=
0
,
t_cur
=
1
,
t_next
=
2
,
iterations
=
atoi
(
argv
[
2
]),
length
=
atoi
(
argv
[
3
]);
double
dx
=
atof
(
argv
[
4
]),
tau
=
atof
(
argv
[
5
]);
STRING_PARTS
=
length
/
dx
;
if
(
!
(
Y
=
(
double
*
)
malloc
(
3
*
STRING_PARTS
*
sizeof
(
double
)))
)
return
2
;
// Initialise the requested shape in the allocated memory.
switch
(
*
argv
[
1
])
{
switch
(
*
argv
[
1
])
{
case
'p'
:
init_pluck
(
a
rgv
);
break
;
case
'p'
:
init_pluck
(
a
tof
(
argv
[
6
]),
length
,
dx
);
break
;
case
's'
:
init_sinus
(
a
rgv
);
break
;
case
's'
:
init_sinus
(
a
toi
(
argv
[
6
])
);
break
;
default:
default:
fprintf
(
stderr
,
"Does this look like a 'p' or 's' to you?
\n
"
);
fprintf
(
stderr
,
"Argument 2 '%s' does not look like a 'p' or 's'.
\n
"
,
argv
[
1
]);
return
1
;
return
1
;
}
}
double
c
=
.
04
,
dt
=
.
1
,
dx
=
.
02
,
// The string is connected at both ends.
C
=
c
*
c
*
(
dt
/
dx
)
*
(
dt
/
dx
);
connect_string_ends
();
// TODO: implement iterations
int
t_prev
=
0
,
t_cur
=
1
,
t_next
=
2
,
T
=
10
;
for
(
int
i
=
0
;
i
<
T
;
i
++
)
{
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
iterate
(
C
,
t_prev
,
t_cur
,
t_next
);
iterate
(
tau
,
t_prev
,
t_cur
,
t_next
);
SWAP
(
t_cur
,
t_next
);
SWAP
(
t_cur
,
t_next
);
SWAP
(
t_prev
,
t_next
);
SWAP
(
t_prev
,
t_next
);
plot
(
t_cur
);
plot
(
t_cur
);
...
...
modsim/ass4_sander/part2/plot.py
100644 → 100755
View file @
62d0f0a8
from
pyplot
import
show
,
fig
#!/usr/bin/env python
from
pylab
import
plot
,
figure
,
clf
,
show
from
sys
import
stdin
lines
=
stdin
.
readlines
()
Y
=
map
(
float
,
lines
[
0
].
split
(
','
))
figure
(
1
)
clf
()
plot
(
Y
,
'-'
)
show
()
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