Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
SWIFT
SWIFTsim
Commits
56d4cda4
Commit
56d4cda4
authored
9 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
added a test for the threadpool, minor bux fixes found using the test.
parent
f324f53d
No related branches found
No related tags found
1 merge request
!176
Tasks cleanup
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/threadpool.h
+3
-3
3 additions, 3 deletions
src/threadpool.h
tests/Makefile.am
+5
-2
5 additions, 2 deletions
tests/Makefile.am
tests/testKernel.c
+1
-1
1 addition, 1 deletion
tests/testKernel.c
tests/threadpool_test.c
+70
-0
70 additions, 0 deletions
tests/threadpool_test.c
with
79 additions
and
6 deletions
src/threadpool.h
+
3
−
3
View file @
56d4cda4
...
...
@@ -43,11 +43,11 @@ struct threadpool {
/* Current map data and count. */
void
*
map_data
,
*
map_extra_data
;
size_t
map_data_count
,
map_data_size
,
map_data_stride
;
threadpool_map_function
map_function
;
volatile
size_t
map_data_count
,
map_data_size
,
map_data_stride
;
volatile
threadpool_map_function
map_function
;
/* Counter for the number of threads that are done. */
int
num_threads_done
;
volatile
int
num_threads_done
;
};
/* Function prototypes. */
...
...
This diff is collapsed.
Click to expand it.
tests/Makefile.am
+
5
−
2
View file @
56d4cda4
...
...
@@ -22,11 +22,12 @@ AM_LDFLAGS = ../src/.libs/libswiftsim.a $(HDF5_LDFLAGS) $(HDF5_LIBS)
# List of programs and scripts to run in the test suite
TESTS
=
testGreetings testReading.sh testSingle testPair.sh testPairPerturbed.sh
\
test27cells.sh test27cellsPerturbed.sh testParser.sh testKernel
test27cells.sh test27cellsPerturbed.sh testParser.sh testKernel
\
threadpool_test
# List of test programs to compile
check_PROGRAMS
=
testGreetings testReading testSingle testTimeIntegration
\
testSPHStep testPair test27cells testParser testKernel
testSPHStep testPair test27cells testParser testKernel
threadpool_test
# Sources for the individual programs
testGreetings_SOURCES
=
testGreetings.c
...
...
@@ -47,6 +48,8 @@ testParser_SOURCES = testParser.c
testKernel_SOURCES
=
testKernel.c
threadpool_test_SOURCES
=
threadpool_test.c
# Files necessary for distribution
EXTRA_DIST
=
testReading.sh makeInput.py testPair.sh testPairPerturbed.sh
\
test27cells.sh test27cellsPerturbed.sh tolerance.dat testParser.sh
\
...
...
This diff is collapsed.
Click to expand it.
tests/testKernel.c
+
1
−
1
View file @
56d4cda4
...
...
@@ -18,7 +18,7 @@
*
******************************************************************************/
#define NO__
AVX
__
#define NO__
SSE2
__
#include
"vector.h"
#include
"swift.h"
...
...
This diff is collapsed.
Click to expand it.
tests/threadpool_test.c
0 → 100644
+
70
−
0
View file @
56d4cda4
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
// Standard includes.
#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
// Local includes.
#include
"../src/threadpool.h"
#include
"../src/atomic.h"
void
map_function_first
(
void
*
map_data
,
void
*
extra_data
)
{
const
int
input
=
*
(
int
*
)
map_data
;
usleep
(
rand
()
%
1000000
);
printf
(
"map_function_first: got input %i.
\n
"
,
input
);
fflush
(
stdout
);
}
void
map_function_second
(
void
*
map_data
,
void
*
extra_data
)
{
const
int
input
=
*
(
int
*
)
map_data
;
usleep
(
rand
()
%
1000000
);
printf
(
"map_function_second: got input %i.
\n
"
,
input
);
fflush
(
stdout
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
// Some constants for this test.
const
int
num_threads
=
16
;
const
int
N
=
20
;
const
int
num_runs
=
2
;
// Create a threadpool with 8 threads.
struct
threadpool
tp
;
threadpool_init
(
&
tp
,
num_threads
);
// Main loop.
for
(
int
run
=
0
;
run
<
num_runs
;
run
++
)
{
// Run over a set of integers and print them.
int
data
[
N
];
for
(
int
k
=
0
;
k
<
N
;
k
++
)
data
[
k
]
=
k
;
printf
(
"processing integers from 0..%i.
\n
"
,
N
);
fflush
(
stdout
);
threadpool_map
(
&
tp
,
map_function_first
,
data
,
N
,
sizeof
(
int
),
NULL
);
// Do the same thing again, with less jobs than threads.
printf
(
"processing integers from 0..%i.
\n
"
,
num_threads
/
2
);
fflush
(
stdout
);
threadpool_map
(
&
tp
,
map_function_second
,
data
,
num_threads
/
2
,
sizeof
(
int
),
NULL
);
}
}
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