forked from saul205/PACS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repo reorganization with Laboratory 3 included
- Loading branch information
Showing
12 changed files
with
214 additions
and
45 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 |
---|---|---|
@@ -1 +1 @@ | ||
build | ||
build* |
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 @@ | ||
cmake_minimum_required (VERSION 3.1) | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") | ||
include(addPacsExecutable) | ||
|
||
project (PACS_EXAMPLES) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
# disable clang-tidy to avoid compilation issues | ||
# set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*") | ||
|
||
|
||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE) | ||
set(THREADS_PREFER_PTHREAD_FLAG TRUE) | ||
find_package(Threads REQUIRED) | ||
|
||
if (MSVC) | ||
# warning level 4 and all warnings as errors | ||
add_compile_options(/W4 /WX) | ||
else() | ||
# lots of warnings and all warnings as errors | ||
add_compile_options(-Wall -Wextra -pedantic -Werror) | ||
endif() | ||
|
||
add_subdirectory(code_examples) | ||
add_subdirectory(Laboratory-3) |
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,2 @@ | ||
ADD_PACS_EXECUTABLE(TARGET pi_taylor_sequential SOURCES pi_taylor_sequential.cc) | ||
ADD_PACS_EXECUTABLE(TARGET pi_taylor_parallel SOURCES pi_taylor_parallel.cc) |
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,54 @@ | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <numeric> | ||
#include <string> | ||
#include <thread> | ||
#include <utility> | ||
#include <vector> | ||
|
||
using my_float = long double; | ||
|
||
void | ||
pi_taylor_chunk(std::vector<my_float> &output, | ||
size_t thread_id, size_t start_step, size_t stop_step) { | ||
|
||
|
||
|
||
} | ||
|
||
std::pair<size_t, size_t> | ||
usage(int argc, const char *argv[]) { | ||
// read the number of steps from the command line | ||
if (argc != 3) { | ||
std::cerr << "Invalid syntax: pi_taylor <steps> <threads>" << std::endl; | ||
exit(1); | ||
} | ||
|
||
size_t steps = std::stoll(argv[1]); | ||
size_t threads = std::stoll(argv[2]); | ||
|
||
if (steps < threads ){ | ||
std::cerr << "The number of steps should be larger than the number of threads" << std::endl; | ||
exit(1); | ||
|
||
} | ||
return std::make_pair(steps, threads); | ||
} | ||
|
||
int main(int argc, const char *argv[]) { | ||
|
||
|
||
auto ret_pair = usage(argc, argv); | ||
auto steps = ret_pair.first; | ||
auto threads = ret_pair.second; | ||
|
||
my_float pi; | ||
|
||
// please complete missing parts | ||
|
||
|
||
std::cout << "For " << steps << ", pi value: " | ||
<< std::setprecision(std::numeric_limits<long double>::digits10 + 1) | ||
<< pi << std::endl; | ||
} | ||
|
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 @@ | ||
#include <iomanip> | ||
#include <iostream> | ||
|
||
// Allow to change the floating point type | ||
using my_float = long double; | ||
|
||
my_float pi_taylor(size_t steps) { | ||
return 0.0f; | ||
} | ||
|
||
int main(int argc, const char *argv[]) { | ||
|
||
// read the number of steps from the command line | ||
if (argc != 2) { | ||
std::cerr << "Invalid syntax: pi_taylor <steps>" << std::endl; | ||
exit(1); | ||
|
||
} | ||
|
||
size_t steps = std::stoll(argv[1]); | ||
auto pi = pi_taylor(steps); | ||
|
||
std::cout << "For " << steps << ", pi value: " | ||
<< std::setprecision(std::numeric_limits<my_float>::digits10 + 1) | ||
<< pi << std::endl; | ||
} |
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
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,9 @@ | ||
macro(ADD_PACS_EXECUTABLE) | ||
set(options "") | ||
set(oneValueArgs TARGET KERNEL) | ||
set(multiValueArgs SOURCES) | ||
cmake_parse_arguments(ADD_PACS_EXECUTABLE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) | ||
|
||
add_executable("${ADD_PACS_EXECUTABLE_TARGET}" ${ADD_PACS_EXECUTABLE_SOURCES}) | ||
target_link_libraries("${ADD_PACS_EXECUTABLE_TARGET}" Threads::Threads) | ||
endmacro(ADD_PACS_EXECUTABLE) |
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 |
---|---|---|
@@ -1,35 +1,9 @@ | ||
cmake_minimum_required (VERSION 3.1) | ||
project (PACS_EXAMPLES) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE) | ||
set(THREADS_PREFER_PTHREAD_FLAG TRUE) | ||
find_package(Threads REQUIRED) | ||
|
||
if (MSVC) | ||
# warning level 4 and all warnings as errors | ||
add_compile_options(/W4 /WX) | ||
else() | ||
# lots of warnings and all warnings as errors | ||
add_compile_options(-Wall -Wextra -pedantic -Werror) | ||
endif() | ||
|
||
#FIXME add macro for the two steps | ||
add_executable(hello_pacs hello_pacs.cc) | ||
target_link_libraries(hello_pacs Threads::Threads) | ||
add_executable(thread_joinable thread_joinable.cc) | ||
target_link_libraries(thread_joinable Threads::Threads) | ||
add_executable(hello_pacs_two_threads hello_pacs_two_threads.cc) | ||
target_link_libraries(hello_pacs_two_threads Threads::Threads) | ||
add_executable(hello_pacs_args hello_pacs_args.cc) | ||
target_link_libraries(hello_pacs_args Threads::Threads) | ||
add_executable(lambda_example lambda_example.cc) | ||
add_executable(saxpy saxpy.cc) | ||
target_link_libraries(saxpy Threads::Threads) | ||
add_executable(saxpy_scaling saxpy_scaling.cc) | ||
target_link_libraries(saxpy_scaling Threads::Threads) | ||
|
||
add_executable(synchronization synchronization.cc) | ||
target_link_libraries(synchronization Threads::Threads) | ||
ADD_PACS_EXECUTABLE(TARGET hello SOURCES hello_pacs.cc) | ||
ADD_PACS_EXECUTABLE(TARGET thread_joinable SOURCES thread_joinable.cc) | ||
ADD_PACS_EXECUTABLE(TARGET hello_pacs_two_threads SOURCES hello_pacs_two_threads.cc) | ||
ADD_PACS_EXECUTABLE(TARGET hello_pacs_args SOURCES hello_pacs_args.cc) | ||
ADD_PACS_EXECUTABLE(TARGET lambda_example SOURCES lambda_example.cc) | ||
ADD_PACS_EXECUTABLE(TARGET saxpy SOURCES saxpy.cc) | ||
ADD_PACS_EXECUTABLE(TARGET saxpy_scaling SOURCES saxpy_scaling.cc) | ||
ADD_PACS_EXECUTABLE(TARGET synchronization SOURCES synchronization.cc) | ||
ADD_PACS_EXECUTABLE(TARGET mutex SOURCES mutex.cc) |
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,25 @@ | ||
#include <iostream> | ||
#include <mutex> | ||
#include <thread> | ||
|
||
namespace { | ||
|
||
std::mutex m; | ||
int shared_var = 0; | ||
} | ||
|
||
void increment() { | ||
m.lock(); | ||
++shared_var; | ||
m.unlock(); | ||
} | ||
|
||
int main() { | ||
std::thread t0{increment}; | ||
std::thread t1{increment}; | ||
|
||
t0.join(); | ||
t1.join(); | ||
|
||
std::cout << shared_var << std::endl; | ||
} |
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,10 @@ | ||
#include <mutex> | ||
|
||
std::mutex m; | ||
int shared_var = 0; | ||
|
||
void increment() { | ||
m.lock(); | ||
++shared_var; | ||
m.unlock(); | ||
} |
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,13 @@ | ||
#include <mutex> | ||
|
||
std::mutex m; | ||
int shared_var = 0; | ||
|
||
void increment() { | ||
|
||
int* siete = new int(7); | ||
|
||
m.lock(); | ||
++shared_var; | ||
m.unlock(); | ||
} |