Skip to content

Commit 04f2f9e

Browse files
committed
Fixed MapReduce build
1 parent 84b263c commit 04f2f9e

25 files changed

+2680
-191
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lesson4/build

Lesson4/Activity10/mapreduce/include/detail/intermediates/in_memory.hpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -257,23 +257,22 @@ class in_memory : detail::noncopyable
257257
}
258258

259259
template<typename T>
260-
bool const insert(T const &key, typename reduce_task_type::value_type const &value)
260+
bool const insert(T const &key, const typename reduce_task_type::value_type &value)
261261
{
262262
return insert(make_intermediate_key<key_type>(key), value);
263263
}
264264

265265
// receive final result
266-
template<typename StoreResult>
267-
bool const insert(typename reduce_task_type::key_type const &key,
268-
typename reduce_task_type::value_type const &value,
266+
bool const insert(const typename reduce_task_type::key_type &key,
267+
const typename reduce_task_type::value_type &value,
269268
StoreResult &store_result)
270269
{
271270
return store_result(key, value) && insert(key, value);
272271
}
273272

274273
// receive intermediate result
275-
bool const insert(typename key_type const &key,
276-
typename reduce_task_type::value_type const &value)
274+
bool const insert(const key_type &key,
275+
const typename reduce_task_type::value_type &value)
277276
{
278277
size_t const partition = (num_partitions_ == 1)? 0 : partitioner_(key, num_partitions_);
279278
auto &map = intermediates_[partition];

Lesson4/Activity10/mapreduce/include/detail/intermediates/local_disk.hpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ struct null_combiner;
1515

1616
namespace detail {
1717

18+
template<typename T> uintmax_t const length(T const &str);
19+
20+
template<>
21+
inline uintmax_t const length(std::string const &str)
22+
{
23+
return str.length();
24+
}
25+
1826
struct file_lines_comp
1927
{
2028
template<typename T>
@@ -481,17 +489,17 @@ class local_disk : detail::noncopyable
481489

482490
// receive final result
483491
template<typename StoreResult>
484-
bool const insert(typename reduce_task_type::key_type const &key,
485-
typename reduce_task_type::value_type const &value,
486-
StoreResult &store_result)
492+
bool const insert(typename reduce_task_type::key_type &key,
493+
typename reduce_task_type::value_type &value,
494+
StoreResult &store_result)
487495
{
488496
store_result(key, value);
489497
return true;
490498
}
491499

492500
// receive intermediate result
493-
bool const insert(typename key_type const &key,
494-
typename reduce_task_type::value_type const &value)
501+
bool const insert(key_type &key,
502+
typename reduce_task_type::value_type &value)
495503
{
496504
size_t const partition = partitioner_(key, num_partitions_);
497505

Lesson4/Activity10/mapreduce/include/mapreduce.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ void run(mapreduce::specification &spec, mapreduce::results &result)
146146
{
147147
typename Job::datasource_type datasource(spec);
148148
Job job(datasource, spec);
149-
job.run<mapreduce::schedule_policy::cpu_parallel<Job> >(result);
149+
job.run(result);
150+
151+
//job.run<mapreduce::schedule_policy::cpu_parallel<Job> >(result);
150152
}
151153

152154
} // namespace mapreduce

Lesson4/CMakeLists.txt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# CMakeList.txt : CMake project for Chapter4, include source and define
2+
# project specific logic here.
3+
#
4+
cmake_minimum_required (VERSION 3.8)
5+
6+
# Look for boost installation
7+
find_package(Boost 1.65 COMPONENTS filesystem iostreams)
8+
find_package(Threads REQUIRED)
9+
10+
# Add source to this project's executable.
11+
add_executable (binary_search "Exercise18/binary_search.cpp")
12+
set_property (TARGET binary_search PROPERTY CXX_STANDARD 14)
13+
14+
add_executable (merge_sort "Exercise19/merge_sort.cpp")
15+
set_property (TARGET merge_sort PROPERTY CXX_STANDARD 14)
16+
17+
add_executable (quick_sort "Exercise20/quick_sort.cpp")
18+
set_property (TARGET quick_sort PROPERTY CXX_STANDARD 14)
19+
20+
add_executable (linear_time_select "Exercise21/linear_time_select.cpp")
21+
set_property (TARGET linear_time_select PROPERTY CXX_STANDARD 14)
22+
23+
add_executable (transform_accumulate "Exercise22/transform_accumulate.cpp")
24+
set_property (TARGET transform_accumulate PROPERTY CXX_STANDARD 14)
25+
26+
if(Boost_FOUND)
27+
add_executable (mapreduce_wordcount "Activity10/mapreduce_wordcount.cpp")
28+
target_include_directories (mapreduce_wordcount PUBLIC Activity10/mapreduce/include ${Boost_INCLUDE_DIRS})
29+
set_property (TARGET mapreduce_wordcount PROPERTY CXX_STANDARD 14)
30+
target_link_libraries (mapreduce_wordcount Boost::filesystem Boost::iostreams Threads::Threads)
31+
32+
add_executable (mapreduce_primecheck "Exercise23/mapreduce_primecheck.cpp")
33+
target_include_directories (mapreduce_primecheck PUBLIC Activity10/mapreduce/include ${Boost_INCLUDE_DIRS})
34+
set_property (TARGET mapreduce_primecheck PROPERTY CXX_STANDARD 14)
35+
target_link_libraries (mapreduce_primecheck Boost::filesystem Boost::iostreams Threads::Threads)
36+
37+
add_executable (mapreduce_wordcount_skeleton "Activity10/mapreduce_wordcount_skeleton.cpp")
38+
target_include_directories (mapreduce_wordcount_skeleton PUBLIC Activity10/mapreduce/include ${Boost_INCLUDE_DIRS})
39+
set_property (TARGET mapreduce_wordcount_skeleton PROPERTY CXX_STANDARD 14)
40+
target_link_libraries (mapreduce_wordcount_skeleton Boost::filesystem Boost::iostreams Threads::Threads)
41+
else()
42+
message("Boost libraries not found! Please install them and try to build again")
43+
endif()
44+
45+
# TODO: Add tests and install targets if needed.

Lesson4/Exercise18/Chapter4.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Chapter4.h : Include file for standard system include files,
2+
// or project specific include files.
3+
4+
#pragma once
5+
6+
#include <iostream>
7+
#include <vector>
8+
#include <chrono>
9+
#include <random>
10+
#include <algorithm>
11+
#include <numeric>

Lesson4/Exercise23/mapreduce.hpp

-170
This file was deleted.

0 commit comments

Comments
 (0)