-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f5d302d
Showing
12 changed files
with
1,405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.swp | ||
*.lo | ||
*.o | ||
*.info | ||
*.la | ||
contrib/lapesd-libgomp |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# Copyright(C) 2015 Pedro H. Penna <pedrohenriquepenna@gmail.com | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 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 General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
# MA 02110-1301, USA. | ||
# | ||
|
||
tar -xjvf lapesd-libgomp-1.5.tar.bz2 | ||
cd lapesd-libgomp | ||
make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright(C) 2015 Pedro H. Penna <pedrohenriquepenna@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 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 General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef BENCHMARK_H_ | ||
#define BENCHMARK_H_ | ||
|
||
/* Forward definitions. */ | ||
extern void benchmark(const unsigned *, unsigned, int, long); | ||
|
||
#endif /* BENCHMARK_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright(C) 2016 Pedro H. Penna <pedrohenriquepenna@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 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 General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef PROFILE_H_ | ||
#define PROFILE_H_ | ||
|
||
/* Forward definitions. */ | ||
extern void profile_start(void); | ||
extern void profile_end(void); | ||
extern void profile_dump(void); | ||
|
||
#endif /* PROFILE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright(C) 2016 Pedro H. Penna <pedrohenriquepenna@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 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 General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef UTIL_H_ | ||
#define UTIL_H_ | ||
|
||
#include <stdlib.h> | ||
|
||
/* Forward definitions. */ | ||
extern void *scalloc(size_t, size_t); | ||
extern void *smalloc(size_t); | ||
extern void *srealloc(void *, size_t); | ||
extern void error(const char *); | ||
|
||
#endif /* UTIL_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# | ||
# Copyright(C) 2016-2017 Pedro H. Penna <pedrohenriquepenna@gmail.com> | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 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 General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
# MA 02110-1301, USA. | ||
|
||
# Directories. | ||
export BINDIR = $(CURDIR)/bin | ||
export INCDIR = $(CURDIR)/include | ||
export SRCDIR = $(CURDIR)/src | ||
|
||
# Toolchain. | ||
export CC = gcc | ||
|
||
# Toolchain configuration. | ||
export CFLAGS += -I $(INCDIR) | ||
export CFLAGS += -ansi -std=c99 -pedantic -fopenmp | ||
export CFLAGS += -Wall -Wextra -Werror | ||
export CFLAGS += -O3 | ||
|
||
# Libraries. | ||
export LIBS = -L contrib/lapesd-libgomp/src/libgomp/build/.libs -lgomp -lm | ||
|
||
# Executable file. | ||
export EXEC = benchmark | ||
|
||
# Builds everything. | ||
all: | ||
mkdir -p $(BINDIR) | ||
$(CC) $(SRCDIR)/*.c $(CFLAGS) -o $(BINDIR)/$(EXEC).out $(LIBS) | ||
|
||
# Cleans compilation files. | ||
clean: | ||
rm -f $(BINDIR)/$(EXEC).out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* | ||
* Copyright(C) 2015 Pedro H. Penna <pedrohenriquepenna@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 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 General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <omp.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include <limits.h> | ||
|
||
#include <profile.h> | ||
#include <util.h> | ||
|
||
#include <benchmark.h> | ||
|
||
extern void omp_set_workload(unsigned *, unsigned); | ||
|
||
/*============================================================================* | ||
* Kernel * | ||
*============================================================================*/ | ||
|
||
/** | ||
* @brief Kernelernel. | ||
* | ||
* @param n Number of operations. | ||
* @param load Load of an operation. | ||
* | ||
* @returns A dummy result. | ||
*/ | ||
static long kernel(unsigned n, long load) | ||
{ | ||
long sum = 0; | ||
|
||
for (unsigned i = 0; i < n; i++) | ||
{ | ||
for (long j = 0; j < load; j++) | ||
sum += i + j; | ||
} | ||
|
||
return (sum); | ||
} | ||
|
||
/*============================================================================* | ||
* Benchmark * | ||
*============================================================================*/ | ||
|
||
/** | ||
* @brief Dumps simulation statistics. | ||
* | ||
* @param respvar Response variable. | ||
* @param nthreads Number of threads. | ||
* @param prefix Prefix for response variable. | ||
*/ | ||
static void benchmark_dump(const double *respvar, int nthreads, const char *prefix) | ||
{ | ||
double min, max, total; | ||
double mean, stddev; | ||
|
||
min = UINT_MAX; max = 0; | ||
total = 0; mean = 0.0; stddev = 0.0; | ||
|
||
/* Compute min, max, total. */ | ||
for (int i = 0; i < nthreads; i++) | ||
{ | ||
double wtotal; | ||
|
||
wtotal = respvar[i]; | ||
|
||
if (min > wtotal) | ||
min = wtotal; | ||
if (max < wtotal) | ||
max = wtotal; | ||
|
||
total += wtotal; | ||
} | ||
|
||
/* Compute mean. */ | ||
mean = ((double) total)/nthreads; | ||
|
||
/* Compute stddev. */ | ||
for (int i = 0; i < nthreads; i++) | ||
stddev += pow(respvar[i] - mean, 2); | ||
stddev = sqrt(stddev/(nthreads)); | ||
|
||
/* Print statistics. */ | ||
printf("%s_min: %lf\n", prefix, min); | ||
printf("%s_max: %lf\n", prefix, max); | ||
printf("%s_mean: %lf\n", prefix, mean); | ||
printf("%s_stddev: %lf\n", prefix, 100*stddev/mean); | ||
printf("%s_imbalance: %lf\n", prefix, 100*(max - min)/((double) total)); | ||
printf("%s_speeddown: %lf\n", prefix, max/((double) min)); | ||
printf("%s_cost: %lf\n", prefix, nthreads*max); | ||
} | ||
|
||
/** | ||
* @brief Synthetic benchmark. | ||
* | ||
* @param tasks Tasks. | ||
* @param ntasks Number of tasks. | ||
* @param nthreads Number of threads. | ||
* @param load Load for constant kernel. | ||
*/ | ||
void benchmark( | ||
const unsigned *tasks, | ||
unsigned ntasks, | ||
int nthreads, | ||
long load) | ||
{ | ||
long sum = 0; | ||
double loads[nthreads]; | ||
double times[nthreads]; | ||
|
||
memset(times, 0, nthreads*sizeof(double)); | ||
|
||
/* Sanity check. */ | ||
assert(tasks != NULL); | ||
assert(nthreads > 0); | ||
assert(load > 0); | ||
|
||
memset(loads, 0, nthreads*sizeof(unsigned)); | ||
|
||
/* Predict workload. */ | ||
unsigned *_tasks; | ||
_tasks = smalloc(ntasks*sizeof(unsigned)); | ||
memcpy(_tasks, tasks, ntasks*sizeof(unsigned)); | ||
|
||
profile_start(); | ||
|
||
/* Sort Each bucket. */ | ||
omp_set_workload(_tasks, ntasks); | ||
|
||
#pragma omp parallel for schedule(runtime) num_threads(nthreads) reduction(+:sum) | ||
for (unsigned i = 0; i < ntasks; i++) | ||
{ | ||
double start = 0.0; | ||
|
||
int tid = omp_get_thread_num(); | ||
|
||
loads[tid] += tasks[i]; | ||
|
||
start = omp_get_wtime(); | ||
sum += kernel(tasks[i], load); | ||
times[tid] += omp_get_wtime() - start; | ||
} | ||
|
||
profile_end(); | ||
profile_dump(); | ||
|
||
benchmark_dump(loads, nthreads, "load"); | ||
benchmark_dump(times, nthreads, "time"); | ||
|
||
/* House keeping. */ | ||
free(_tasks); | ||
} |
Oops, something went wrong.