Initial entry
This commit is contained in:
parent
bd8e1da154
commit
7ee3419f2b
59
CMakeLists.txt
Normal file
59
CMakeLists.txt
Normal file
@ -0,0 +1,59 @@
|
||||
# copyright (C) 2022, E. Wes Bethel
|
||||
|
||||
cmake_minimum_required( VERSION 3.5)
|
||||
|
||||
project (sum_harness_instructional LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
#set(CMAKE_CXX_FLAGS "-Wall") # uncomment this line to turn on compiler warnings
|
||||
|
||||
# info for setting the compiler optimization level
|
||||
|
||||
# option 1 (best approach): set the CMAKE_CXX_FLAGS_RELEASE environment variable then run cmake
|
||||
|
||||
# for full optimization:
|
||||
# bash users:
|
||||
# % export CMAKE_CXX_FLAGS_RELEASE="-O3"
|
||||
# csh users:
|
||||
# % setenv CMAKE_CXX_FLAGS_RELEASE "-O3"
|
||||
|
||||
# for no optimization:
|
||||
# bash users:
|
||||
# % export CMAKE_CXX_FLAGS_RELEASE="-O0"
|
||||
# csh users:
|
||||
# % setenv CMAKE_CXX_FLAGS_RELEASE "-O0"
|
||||
|
||||
|
||||
# option 2 (works but not preferred): uncomment one of the following two lines then run/rerun cmake:
|
||||
|
||||
# -O3 is full optimization in gcc/g++
|
||||
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||
# -O0 is no optimization in gcc/g++
|
||||
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O0")
|
||||
|
||||
|
||||
#
|
||||
# start of cmake rules: you shouldn't need to modify anything below here
|
||||
|
||||
# common library target for benchmarking
|
||||
add_library(benchmark OBJECT benchmark.cpp)
|
||||
target_compile_features(benchmark PRIVATE cxx_std_11)
|
||||
|
||||
add_executable (sum_direct sum_direct.cpp)
|
||||
target_link_libraries(sum_direct PRIVATE benchmark)
|
||||
target_compile_features(sum_direct PRIVATE cxx_std_11)
|
||||
target_compile_options(sum_direct PRIVATE -Wall -pedantic -march=native)
|
||||
#set(BENCHMARK "direct")
|
||||
#configure_file(job.in job-${BENCHMARK})
|
||||
|
||||
add_executable (sum_vector sum_vector.cpp)
|
||||
target_link_libraries(sum_vector PRIVATE benchmark)
|
||||
target_compile_features(sum_vector PRIVATE cxx_std_11)
|
||||
target_compile_options(sum_vector PRIVATE -Wall -pedantic -march=native)
|
||||
|
||||
add_executable (sum_indirect sum_indirect.cpp)
|
||||
target_link_libraries(sum_indirect PRIVATE benchmark)
|
||||
target_compile_features(sum_indirect PRIVATE cxx_std_11)
|
||||
target_compile_options(sum_indirect PRIVATE -Wall -pedantic -march=native)
|
||||
|
||||
# EOF
|
||||
95
README.md
95
README.md
@ -1,2 +1,93 @@
|
||||
# sum_harness_instructional
|
||||
Code harness for 3 different methods of computing a sum
|
||||
Readme file for sum_harness_instructional
|
||||
|
||||
# sum_harness_instructional code harness
|
||||
|
||||
This directory contains a benchmark harness for testing different implementations of
|
||||
summing numbers.
|
||||
|
||||
A single high-level main() is present in the benchmark.cpp file, which has definitions of proble3m sizes and so forth.
|
||||
|
||||
This main() will make calls to two routines that must be provided by your code:
|
||||
* setup(N, A) // where you initialize N values in A
|
||||
* result = sum(N, A) // where you compute the sum of N values in A and return the answer
|
||||
|
||||
This harness will generate three different executables using the one benchmark.cpp containing main(), and then using sum_direct.cpp, sum_indirect.cpp, or sum_vector.cpp.
|
||||
|
||||
Your job is to:
|
||||
|
||||
* Add code for setup() and sum() in each of sum_direct.cpp, sum_indirect.cpp, and sum_vector.cpp
|
||||
* Add instrumention code in benchmark.cpp to measure elapsed time for the call to the sum() routine
|
||||
|
||||
You should not need to modify anything inside CMakeLists.txt.
|
||||
|
||||
# Default build instructions:
|
||||
|
||||
|
||||
% cd sum_harness_instructional # contains the source files and CMakeLists.txt file
|
||||
|
||||
% mkdir build
|
||||
|
||||
% cd build
|
||||
|
||||
% cmake ../ # cmake generates lots of output
|
||||
|
||||
% make # to build the programs
|
||||
|
||||
# Additional build options -- Compiler Optimization Level
|
||||
|
||||
By default, the CMakeLists.txt will do a "Release" build, which means there will be full compiler optimizations.
|
||||
|
||||
There are two methods for modifying the compiler optimization level.
|
||||
|
||||
Option 1 (best approach): set the CMAKE_CXX_FLAGS_RELEASE environment variable then run cmake
|
||||
|
||||
For full optimization:
|
||||
bash users:
|
||||
% export CMAKE_CXX_FLAGS_RELEASE="-O3"
|
||||
csh users:
|
||||
% setenv CMAKE_CXX_FLAGS_RELEASE "-O3"
|
||||
|
||||
For no optimization:
|
||||
bash users:
|
||||
% export CMAKE_CXX_FLAGS_RELEASE="-O0"
|
||||
csh users:
|
||||
% setenv CMAKE_CXX_FLAGS_RELEASE "-O0"
|
||||
|
||||
|
||||
Option 2 (works but not preferred): uncomment one of the following two lines then run/rerun cmake:
|
||||
|
||||
For -O3: full optimization
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||
For -O0: no optimization in gcc/g++
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O0")
|
||||
|
||||
Note: if you modify CMakeLists.txt, you will need to rerun cmake and then rerun make. If you need to rerun cmake, it is best to delete everything in the build directory and start from scratch (\rm -rf).
|
||||
|
||||
|
||||
# Adding your code
|
||||
|
||||
You will need to add code in three places:
|
||||
|
||||
* Inside benchmark.cpp: please add instrumentation code that will measure and report elapsed time consumed by the call to the sum() routine. Please refer to the chrono_timer code for an example of how to do this kind of time measurement.
|
||||
|
||||
* The setup() routine inside each of sum_direct.cpp, sum_indirect.cpp, and sum_vector.cpp. See the homework writeup for details on how to perform initialization for each of these different codes.
|
||||
|
||||
* The sum() routine inside each of sum_direct.cpp, sum_indirect.cpp, and sum_vector.cpp. See the homework writeup for details on how to perform the sum operation for each of these different codes.
|
||||
|
||||
# Running the codes
|
||||
|
||||
Once the codes are built, you should be able to just run each one from the command line:
|
||||
|
||||
% ./sum_direct
|
||||
|
||||
or
|
||||
|
||||
% ./sum_indirect
|
||||
|
||||
or
|
||||
|
||||
% ./sum_vector
|
||||
|
||||
When you run each code, it will iterate through the set of problem sizes predefined inside benchmark.cpp
|
||||
|
||||
# EOF
|
||||
|
||||
70
benchmark.cpp
Normal file
70
benchmark.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// (C) 2022, E. Wes Bethel
|
||||
// benchmark-* harness for running different versions of the sum study
|
||||
// over different problem sizes
|
||||
//
|
||||
// usage: no command line arguments
|
||||
// set problem sizes, block sizes in the code below
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
extern void setup(int64_t N, uint64_t A[]);
|
||||
extern int64_t sum(int64_t N, uint64_t A[]);
|
||||
|
||||
/* The benchmarking program */
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::cout << std::fixed << std::setprecision(2);
|
||||
|
||||
printf(" hello world \n");
|
||||
std::vector<int> test_sizes{64, 128, 256, 512, 1024, 2048};
|
||||
|
||||
//#define MAX_PROBLEM_SIZE 500000000
|
||||
|
||||
|
||||
//#define MAX_PROBLEM_SIZE 1 << 20 // 1M
|
||||
//#define MAX_PROBLEM_SIZE 1 << 24 // 16M
|
||||
//#define MAX_PROBLEM_SIZE 1 << 27 // 128M
|
||||
#define MAX_PROBLEM_SIZE 1 << 28 // 256M
|
||||
//#define MAX_PROBLEM_SIZE 1 << 30 // 1 G
|
||||
//std::vector<int64_t> problem_sizes{100000, 500000, 1000000, 5000000, 10000000, 50000000, 100000000, MAX_PROBLEM_SIZE};
|
||||
//std::vector<int64_t> problem_sizes{ MAX_PROBLEM_SIZE};
|
||||
std::vector<int64_t> problem_sizes{ MAX_PROBLEM_SIZE >> 5, MAX_PROBLEM_SIZE >> 4, MAX_PROBLEM_SIZE >> 3, MAX_PROBLEM_SIZE >> 2, MAX_PROBLEM_SIZE >> 1, MAX_PROBLEM_SIZE};
|
||||
|
||||
std::vector<uint64_t> A(MAX_PROBLEM_SIZE);
|
||||
|
||||
//int A[MAX_PROBLEM_SIZE]; // buffer big enough for all problem sizes
|
||||
// int A[MAX_PROBLEM_SIZE]; // buffer big enough for all problem sizes
|
||||
int64_t t;
|
||||
int n_problems = problem_sizes.size();
|
||||
|
||||
printf(" hello world again \n");
|
||||
|
||||
/* For each test size */
|
||||
for (int n : problem_sizes)
|
||||
{
|
||||
printf("Working on problem size N=%d \n", n);
|
||||
|
||||
// invoke user code to set up the problem
|
||||
setup(n, &A[0]);
|
||||
|
||||
// insert timer code here
|
||||
|
||||
// invoke method to perform the sum
|
||||
t = sum(n, &A[0]);
|
||||
|
||||
// insert end timer code here, and print out elapsed time for this problem size
|
||||
|
||||
printf(" Sum result = %lld \n",t);
|
||||
|
||||
} // end loop over problem sizes
|
||||
}
|
||||
|
||||
// EOF
|
||||
24
sum_direct.cpp
Normal file
24
sum_direct.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
void
|
||||
setup(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside direct_sum problem_setup, N=%lld \n", N);
|
||||
}
|
||||
|
||||
int64_t
|
||||
sum(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside direct_sum perform_sum, N=%lld \n", N);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
24
sum_indirect.cpp
Normal file
24
sum_indirect.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
void
|
||||
setup(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside sum_indirect problem_setup, N=%lld \n", N);
|
||||
}
|
||||
|
||||
int64_t
|
||||
sum(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside sum_indirect perform_sum, N=%lld \n", N);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
24
sum_vector.cpp
Normal file
24
sum_vector.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
void
|
||||
setup(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside sum_vector problem_setup, N=%lld \n", N);
|
||||
}
|
||||
|
||||
int64_t
|
||||
sum(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside sum_vector perform_sum, N=%lld \n", N);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user