Skip to content
Snippets Groups Projects
Commit 56d4cda4 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

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!176Tasks cleanup
......@@ -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. */
......
......@@ -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 \
......
......@@ -18,7 +18,7 @@
*
******************************************************************************/
#define NO__AVX__
#define NO__SSE2__
#include "vector.h"
#include "swift.h"
......
/*******************************************************************************
* 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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment