Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
boids
boids4
Commits
6595b33a
Commit
6595b33a
authored
Nov 11, 2015
by
Cassio Kirch
Browse files
Array name is in plural.
parent
0d80246f
Changes
3
Hide whitespace changes
Inline
Side-by-side
main.c
View file @
6595b33a
...
...
@@ -76,8 +76,8 @@ getGamma (const struct Boid* const boids)
void
one_system
()
{
struct
Boid
boid
[
N
];
struct
Box
box
[
BOXES
];
struct
Boid
boid
s
[
N
];
struct
Box
box
es
[
BOXES
];
unsigned
int
boidCount
,
boxID
,
threadCount
;
unsigned
long
long
int
step
,
continuousStep
=
0
;
...
...
@@ -110,32 +110,32 @@ one_system ()
((
int
)
N
/
(
int
)
NUM_THREADS
);
if
(
threadCount
==
NUM_THREADS
-
1
)
parametersStruct
[
threadCount
].
right
+=
N
%
NUM_THREADS
;
parametersStruct
[
threadCount
].
boid
=
boid
;
parametersStruct
[
threadCount
].
box
=
box
;
parametersStruct
[
threadCount
].
boid
s
=
boid
s
;
parametersStruct
[
threadCount
].
box
es
=
box
es
;
parameters
[
threadCount
]
=
&
(
parametersStruct
[
threadCount
]);
}
for
(
boidCount
=
0
;
boidCount
<
N
;
boidCount
++
)
{
initializeBoid
(
&
boid
[
boidCount
]);
checkLimits
(
&
(
boid
[
boidCount
]));
initializeBoid
(
&
boid
s
[
boidCount
]);
checkLimits
(
&
(
boid
s
[
boidCount
]));
}
initializeBoxes
(
box
);
initializeBoxes
(
box
es
);
for
(
boidCount
=
0
;
boidCount
<
N
;
boidCount
++
)
appendBoid
(
&
(
boid
[
boidCount
]),
box
);
appendBoid
(
&
(
boid
s
[
boidCount
]),
box
es
);
for
(
step
=
0
;
step
<=
STEPS
;
++
step
)
{
nextStep
(
parameters
);
for
(
boidCount
=
0
;
boidCount
<
N
;
boidCount
++
)
{
checkLimits
(
&
(
boid
[
boidCount
]));
boxID
=
getBoxID
(
boid
[
boidCount
]);
if
(
boid
[
boidCount
].
boxID
!=
boxID
)
checkLimits
(
&
(
boid
s
[
boidCount
]));
boxID
=
getBoxID
(
boid
s
[
boidCount
]);
if
(
boid
s
[
boidCount
].
boxID
!=
boxID
)
{
removeBoid
(
&
boid
[
boidCount
],
box
);
appendBoid
(
&
boid
[
boidCount
],
box
);
removeBoid
(
&
boid
s
[
boidCount
],
box
es
);
appendBoid
(
&
boid
s
[
boidCount
],
box
es
);
}
}
if
(
step
%
EXIT_INTERVAL
==
0
)
...
...
@@ -143,7 +143,7 @@ one_system ()
printf
(
"Step: %llu
\n
"
,
step
);
#ifdef COUNT_NEIGHBORS
fprintf
(
averageNeighborsFile
,
"%llu
\t
%lf
\n
"
,
step
,
getAverageNeighborsNo
(
boid
));
fprintf
(
averageNeighborsFile
,
"%llu
\t
%lf
\n
"
,
step
,
getAverageNeighborsNo
(
boid
s
));
#endif
#ifdef PLOT_EXIT_FILES
...
...
@@ -153,28 +153,28 @@ one_system ()
{
/*fprintf(godFile, "%llu\t" "%llu\t" "%u\t" "%u\t" \
"%lf\t" "%lf\n", continuousStep, step, \
boid[boidCount].type, boidCount, \
boid[boidCount].position[X], \
boid[boidCount].position[Y]);
boid
s
[boidCount].type, boidCount, \
boid
s
[boidCount].position[X], \
boid
s
[boidCount].position[Y]);
*/
if
(
boid
[
boidCount
].
type
==
ENDODERM
)
if
(
boid
s
[
boidCount
].
type
==
ENDODERM
)
fprintf
(
endoFile
,
"%u
\t
"
"%u
\t
"
"%lf
\t
"
"%lf
\n
"
,
\
boid
[
boidCount
].
type
,
\
boidCount
,
boid
[
boidCount
].
position
[
X
],
\
boid
[
boidCount
].
position
[
Y
]);
boid
s
[
boidCount
].
type
,
\
boidCount
,
boid
s
[
boidCount
].
position
[
X
],
\
boid
s
[
boidCount
].
position
[
Y
]);
else
fprintf
(
ectoFile
,
"%u
\t
"
"%u
\t
"
"%lf
\t
"
"%lf
\n
"
,
\
boid
[
boidCount
].
type
,
\
boidCount
,
boid
[
boidCount
].
position
[
X
],
\
boid
[
boidCount
].
position
[
Y
]);
boid
s
[
boidCount
].
type
,
\
boidCount
,
boid
s
[
boidCount
].
position
[
X
],
\
boid
s
[
boidCount
].
position
[
Y
]);
}
fclose
(
endoFile
);
fclose
(
ectoFile
);
#endif
#ifdef GAMMA_FILE
fprintf
(
gammaFile
,
"%llu
\t
%lf
\n
"
,
step
,
getGamma
(
boid
));
fprintf
(
gammaFile
,
"%llu
\t
%lf
\n
"
,
step
,
getGamma
(
boid
s
));
#endif
++
continuousStep
;
}
...
...
@@ -194,9 +194,9 @@ one_system ()
{
fprintf
(
finalConfigurationFile
,
\
"%u
\t
"
"%u
\t
"
"%lf
\t
"
"%lf
\n
"
,
\
boid
[
boidCount
].
type
,
boidCount
,
\
boid
[
boidCount
].
position
[
X
],
\
boid
[
boidCount
].
position
[
Y
]);
boid
s
[
boidCount
].
type
,
boidCount
,
\
boid
s
[
boidCount
].
position
[
X
],
\
boid
s
[
boidCount
].
position
[
Y
]);
}
fclose
(
finalConfigurationFile
);
}
...
...
main.h
View file @
6595b33a
...
...
@@ -7,9 +7,9 @@ struct Parameters
unsigned
int
threadID
;
unsigned
int
left
;
unsigned
int
right
;
struct
Boid
*
boid
;
struct
Boid
*
boid
s
;
struct
Boid
*
firstEndoBoid
;
struct
Box
*
box
;
struct
Box
*
box
es
;
};
#define PARAMETERS_STRUCT
#endif
nextstep.c
View file @
6595b33a
...
...
@@ -80,8 +80,8 @@ makeSum (struct Boid* const boid, const struct Boid* conductor, \
}
void
setNextVelocity
(
struct
Boid
*
const
boid
,
const
struct
Box
box
[]
)
/* Where 'boid' is address of a single struct and box is a array. */
setNextVelocity
(
struct
Boid
*
const
boid
,
const
struct
Box
*
box
es
)
/* Where 'boid' is address of a single struct and
'
box
es'
is a array. */
{
double
sumV
[]
=
{
0
.
0
,
0
.
0
};
/* For alpha and velocity sum. */
double
uAngle
,
u
[
2
];
/* For eta and random things. */
...
...
@@ -96,39 +96,39 @@ setNextVelocity (struct Boid* const boid, const struct Box box[])
#endif
/* check neighbors in the same box */
conductor
=
box
[
boid
->
boxID
].
first
;
conductor
=
box
es
[
boid
->
boxID
].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the north box */
conductor
=
box
[
getNorthBoxID
(
boid
->
boxID
)].
first
;
conductor
=
box
es
[
getNorthBoxID
(
boid
->
boxID
)].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the south box */
conductor
=
box
[
getSouthBoxID
(
boid
->
boxID
)].
first
;
conductor
=
box
es
[
getSouthBoxID
(
boid
->
boxID
)].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the west box */
conductor
=
box
[
getWestBoxID
(
boid
->
boxID
)].
first
;
conductor
=
box
es
[
getWestBoxID
(
boid
->
boxID
)].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the east box */
conductor
=
box
[
getEastBoxID
(
boid
->
boxID
)].
first
;
conductor
=
box
es
[
getEastBoxID
(
boid
->
boxID
)].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the northeast box */
conductor
=
box
[
getEastBoxID
(
getNorthBoxID
(
boid
->
boxID
))].
first
;
conductor
=
box
es
[
getEastBoxID
(
getNorthBoxID
(
boid
->
boxID
))].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the southeast box */
conductor
=
box
[
getEastBoxID
(
getSouthBoxID
(
boid
->
boxID
))].
first
;
conductor
=
box
es
[
getEastBoxID
(
getSouthBoxID
(
boid
->
boxID
))].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the northwest box */
conductor
=
box
[
getWestBoxID
(
getNorthBoxID
(
boid
->
boxID
))].
first
;
conductor
=
box
es
[
getWestBoxID
(
getNorthBoxID
(
boid
->
boxID
))].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
/* check neighbors in the southwest box */
conductor
=
box
[
getWestBoxID
(
getSouthBoxID
(
boid
->
boxID
))].
first
;
conductor
=
box
es
[
getWestBoxID
(
getSouthBoxID
(
boid
->
boxID
))].
first
;
makeSum
(
boid
,
conductor
,
sumF
,
sumV
);
uAngle
=
RANDOM_0
(
PI
*
2
.
0
);
...
...
@@ -162,14 +162,14 @@ void*
callNextPositionThread
(
void
*
const
input
)
{
const
struct
Parameters
*
const
parameters
=
input
;
struct
Boid
*
const
boid
=
parameters
->
boid
;
/* struct Boid array. */
//struct Box* const box = parameters -> box; /* struct Box array. */
struct
Boid
*
const
boid
s
=
parameters
->
boid
s
;
/* struct Boid array. */
//struct Box* const box
es
= parameters -> box
es
; /* struct Box array. */
unsigned
int
boidCount
;
for
(
boidCount
=
parameters
->
left
;
boidCount
<
parameters
->
right
;
++
boidCount
)
setNextPosition
((
boid
+
boidCount
));
setNextPosition
((
boid
s
+
boidCount
));
return
NULL
;
}
...
...
@@ -177,13 +177,13 @@ void*
callNextVelocityThread
(
void
*
input
)
{
const
struct
Parameters
*
const
parameters
=
input
;
struct
Boid
*
const
boid
=
parameters
->
boid
;
/* struct Boid array. */
struct
Box
*
const
box
=
parameters
->
box
;
/* struct Box array. */
struct
Boid
*
const
boid
s
=
parameters
->
boid
s
;
/* struct Boid array. */
struct
Box
*
const
box
es
=
parameters
->
box
es
;
/* struct Box array. */
unsigned
int
boidCount
;
for
(
boidCount
=
parameters
->
left
;
boidCount
<
parameters
->
right
;
++
boidCount
)
setNextVelocity
(
boid
+
boidCount
,
box
);
setNextVelocity
(
boid
s
+
boidCount
,
box
es
);
return
NULL
;
}
...
...
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