Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs267
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
recolic-hust
cs267
Commits
38d8d906
There was an error fetching the commit references. Please try again later.
Unverified
Commit
38d8d906
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
fix merge problems
parent
d47be0d5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
hw2/array_test
+0
-0
0 additions, 0 deletions
hw2/array_test
hw2/serial.cpp
+10
-202
10 additions, 202 deletions
hw2/serial.cpp
with
11 additions
and
202 deletions
.gitignore
+
1
−
0
View file @
38d8d906
...
...
@@ -17,6 +17,7 @@ hw2/prof
hw2/autograder
hw2/hackaday_hw2
hw2/mpi
hw2/array_test
*.log
.vscode
*.tar.gz
This diff is collapsed.
Click to expand it.
hw2/array_test
deleted
100755 → 0
+
0
−
0
View file @
d47be0d5
File deleted
This diff is collapsed.
Click to expand it.
hw2/serial.cpp
+
10
−
202
View file @
38d8d906
#include
"common.h"
#include
<cassert>
#include
<iostream>
#include
<cmath>
#include
<cstdio>
#include
<cstdlib>
#include
<vector>
#include
<utility>
#include
<memory>
//
// benchmarking program
//
int
main
(
int
argc
,
char
**
argv
)
{
int
navg
,
nabsavg
=
0
;
double
davg
,
dmin
,
absmin
=
1.0
,
absavg
=
0.0
;
if
(
find_option
(
argc
,
argv
,
"-h"
)
>=
0
)
{
printf
(
"Options:
\n
"
);
printf
(
"-h to see this help
\n
"
);
printf
(
"-n <int> to set the number of particles
\n
"
);
printf
(
"-o <filename> to specify the output file name
\n
"
);
printf
(
"-s <filename> to specify a summary file name
\n
"
);
printf
(
"-no turns off all correctness checks and particle output
\n
"
);
return
0
;
}
int
n
=
read_int
(
argc
,
argv
,
"-n"
,
1000
);
char
*
savename
=
read_string
(
argc
,
argv
,
"-o"
,
NULL
);
char
*
sumname
=
read_string
(
argc
,
argv
,
"-s"
,
NULL
);
FILE
*
fsave
=
savename
?
fopen
(
savename
,
"w"
)
:
NULL
;
FILE
*
fsum
=
sumname
?
fopen
(
sumname
,
"a"
)
:
NULL
;
particle_t
*
particles
=
(
particle_t
*
)
malloc
(
n
*
sizeof
(
particle_t
));
set_size
(
n
);
init_particles
(
n
,
particles
);
double
density
=
0.0005
;
double
cutoff
=
0.01
;
double
size
=
sqrt
(
density
*
n
);
int
sx
=
floor
(
size
/
cutoff
+
2
);
int
sy
=
sx
;
std
::
printf
(
"RDEBUG> grid_size = %d
\n
"
,
sx
);
//std::vector<int> dict[sx][sy];
using
dict_element_type
=
std
::
vector
<
int
>
;
// BAD PRACTICE! You should represent ndArray with only 1 vector.
std
::
vector
<
std
::
vector
<
dict_element_type
>>
dict
(
sx
,
std
::
vector
<
dict_element_type
>
(
sy
));
//
// simulate a number of time steps
//
double
simulation_time
=
read_timer
();
for
(
int
step
=
0
;
step
<
NSTEPS
;
step
++
)
{
navg
=
0
;
davg
=
0.0
;
dmin
=
1.0
;
//
// Update bins
//
for
(
int
i
=
0
;
i
<
sx
;
i
++
)
{
for
(
int
j
=
0
;
j
<
sy
;
j
++
)
{
dict
[
i
][
j
].
clear
();
}
}
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
a
=
floor
(
particles
[
i
].
x
/
cutoff
);
int
b
=
floor
(
particles
[
i
].
y
/
cutoff
);
dict
[
a
][
b
].
push_back
(
i
);
}
//
// compute forces
//
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
a
=
floor
(
particles
[
i
].
x
/
cutoff
);
int
b
=
floor
(
particles
[
i
].
y
/
cutoff
);
particles
[
i
].
ax
=
particles
[
i
].
ay
=
0
;
for
(
int
j
=
0
;
j
<
dict
[
a
][
b
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
][
b
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
if
(
b
>
0
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
][
b
-
1
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
][
b
-
1
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
}
if
(
b
<
sy
-
1
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
][
b
+
1
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
][
b
+
1
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
}
if
(
a
>
0
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
-
1
][
b
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
-
1
][
b
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
if
(
b
>
0
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
-
1
][
b
-
1
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
-
1
][
b
-
1
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
}
if
(
b
<
sy
-
1
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
-
1
][
b
+
1
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
-
1
][
b
+
1
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
}
}
if
(
a
<
sx
-
1
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
+
1
][
b
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
+
1
][
b
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
if
(
b
>
0
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
+
1
][
b
-
1
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
+
1
][
b
-
1
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
}
if
(
b
<
sy
-
1
)
{
for
(
int
j
=
0
;
j
<
dict
[
a
+
1
][
b
+
1
].
size
();
j
++
)
{
apply_force
(
particles
[
i
],
particles
[
dict
[
a
+
1
][
b
+
1
][
j
]],
&
dmin
,
&
davg
,
&
navg
);
}
}
}
}
//
// move particles
//
for
(
int
i
=
0
;
i
<
n
;
i
++
)
::
move
(
particles
[
i
]);
if
(
find_option
(
argc
,
argv
,
"-no"
)
==
-
1
)
{
//
// Computing statistical data
//
if
(
navg
)
{
absavg
+=
davg
/
navg
;
nabsavg
++
;
}
if
(
dmin
<
absmin
)
absmin
=
dmin
;
//
// save if necessary
//
if
(
fsave
&&
(
step
%
SAVEFREQ
)
==
0
)
save
(
fsave
,
n
,
particles
);
}
}
simulation_time
=
read_timer
()
-
simulation_time
;
printf
(
"n = %d, simulation time = %g seconds"
,
n
,
simulation_time
);
if
(
find_option
(
argc
,
argv
,
"-no"
)
==
-
1
)
{
if
(
nabsavg
)
absavg
/=
nabsavg
;
//
// -The minimum distance absmin between 2 particles during the run of the
// simulation -A Correct simulation will have particles stay at greater
// than 0.4 (of cutoff) with typical values between .7-.8 -A simulation
// where particles don't interact correctly will be less than 0.4 (of
// cutoff) with typical values between .01-.05
//
// -The average distance absavg is ~.95 when most particles are interacting
// correctly and ~.66 when no particles are interacting
//
printf
(
", absmin = %lf, absavg = %lf"
,
absmin
,
absavg
);
if
(
absmin
<
0.4
)
printf
(
"
\n
The minimum distance is below 0.4 meaning that some particle "
"is not interacting"
);
if
(
absavg
<
0.8
)
printf
(
"
\n
The average distance is below 0.8 meaning that most particles "
"are not interacting"
);
}
printf
(
"
\n
"
);
//
// Printing summary data
//
if
(
fsum
)
fprintf
(
fsum
,
"%d %g
\n
"
,
n
,
simulation_time
);
//
// Clearing space
//
if
(
fsum
)
fclose
(
fsum
);
free
(
particles
);
if
(
fsave
)
fclose
(
fsave
);
return
0
;
#include
<assert.h>
#include
<math.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
"grid.hpp"
namespace
r267
{
using
namespace
serial
;
}
#include
"impl.inc"
\ No newline at end of file
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