-
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.
now working, macos (m1 chip) compilation falls back to sequential LOL
- Loading branch information
1 parent
4e91692
commit cbc7e97
Showing
11 changed files
with
332 additions
and
148 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,18 +1,27 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
# Set the project name | ||
project(OpenQCD++) | ||
|
||
# Specify the C++ standard | ||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
set(CMAKE_CXX_STANDARD 20) # This is necessary for the std::execution policies. | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
# Specify the compilers | ||
set(CMAKE_C_COMPILER "clang") | ||
set(CMAKE_CXX_COMPILER "clang++") | ||
|
||
# Ensure the GCC standard library is used | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20") | ||
|
||
|
||
|
||
# Add the executables | ||
add_executable(init_print_lattice app/init_print_lattice/main.cpp modules/lattice/LatticeField.cpp) | ||
add_executable(randomize app/randomize/main.cpp modules/lattice/LatticeField.cpp) | ||
add_executable(compute_plaquette app/compute_plaquette/main.cpp modules/lattice/LatticeField.cpp modules/gauge/GaugeField.cpp) | ||
add_executable(randomize app/parallel_computations/randomize.cpp modules/lattice/LatticeField.cpp) | ||
add_executable(apply_func app/parallel_computations/apply_func.cpp modules/lattice/LatticeField.cpp) | ||
add_executable(reduce_if app/parallel_computations/reduce_if.cpp modules/lattice/LatticeField.cpp) | ||
|
||
# Include directories | ||
target_include_directories(init_print_lattice PRIVATE include) | ||
target_include_directories(randomize PRIVATE include) | ||
target_include_directories(compute_plaquette PRIVATE include) | ||
target_include_directories(apply_func PRIVATE include) | ||
target_include_directories(reduce_if PRIVATE include) |
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
// This program performs some examples of the parallel computations that can be done with the | ||
// LatticeField class. | ||
// As examples, this performs and times: | ||
// - Parallel application of a function (an exp) to each element of the lattice field. | ||
|
||
#include "lattice/LatticeField.h" | ||
#include <complex> | ||
#include <chrono> | ||
#include <iostream> | ||
#include <cmath> | ||
#include <fstream> | ||
#include <vector> | ||
#include <functional> | ||
|
||
int main() { | ||
using namespace std::chrono; | ||
|
||
std::ofstream csv_file("apply_func_times.csv"); | ||
csv_file << "Parallel_exp [ms], Sequential_exp [ms]\n"; | ||
|
||
for (int i = 0; i < 100; ++i) { | ||
// Create a lattice field of size 8x8x8x8 with initial value 0.0 | ||
LatticeField<double> lattice(8, 8, 8, 8, 0.0); | ||
|
||
// Randomize the lattice field | ||
lattice.randomize(); | ||
|
||
// Apply exp function to each element of the lattice field in parallel | ||
const auto start = high_resolution_clock::now(); | ||
lattice.func([](double& val) { | ||
val = std::exp(val); | ||
}); | ||
const auto end = high_resolution_clock::now(); | ||
auto timed_parallel_exp = duration_cast<microseconds>(end - start).count(); | ||
|
||
// Randomize the lattice field | ||
lattice.randomize(); | ||
|
||
// Apply exp function to each element of the lattice field in parallel | ||
const auto start_s = high_resolution_clock::now(); | ||
lattice.func_sequential([](double& val) { | ||
val = std::exp(val); | ||
}); | ||
const auto end_s = high_resolution_clock::now(); | ||
auto timed_seq_exp = duration_cast<microseconds>(end_s - start_s).count(); | ||
|
||
|
||
// Write the times to the CSV file | ||
csv_file << timed_parallel_exp << ", " << timed_seq_exp << "\n"; | ||
} | ||
|
||
csv_file.close(); | ||
std::cout << "Timing results have been written to apply_func_times.csv" << std::endl; | ||
|
||
return 0; | ||
} |
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,45 @@ | ||
// This program performs some examples of the parallel computations that can be done with the | ||
// LatticeField class. | ||
// As examples, this performs and times: | ||
// - Randomization of a lattice field. | ||
|
||
#include "lattice/LatticeField.h" | ||
#include <complex> | ||
#include <chrono> | ||
#include <iostream> | ||
#include <cmath> | ||
#include <fstream> | ||
#include <vector> | ||
#include <functional> | ||
|
||
int main() { | ||
using namespace std::chrono; | ||
|
||
std::ofstream csv_file("randomize_times.csv"); | ||
csv_file << "Randomization_par_unseq [ms], Randomization_seq [ms]\n"; | ||
|
||
for (int i = 0; i < 100; ++i) { | ||
// Create a lattice field of size 4x4x4x4 with initial value 0.0 | ||
LatticeField<double> lattice(8, 8, 8, 8, 0.0); | ||
|
||
// Parallel Randomize the lattice field | ||
const auto start = high_resolution_clock::now(); | ||
lattice.randomize(); | ||
const auto end = high_resolution_clock::now(); | ||
auto timed_randomize_parallel = duration_cast<microseconds>(end - start).count(); | ||
|
||
// Randomize the lattice field | ||
auto start_time = high_resolution_clock::now(); | ||
lattice.randomize_sequential(); | ||
auto end_time = high_resolution_clock::now(); | ||
auto timed_randomize_sequential = duration_cast<microseconds>(end_time - start_time).count(); | ||
|
||
// Write the times to the CSV file | ||
csv_file << timed_randomize_parallel << "," << timed_randomize_sequential << "\n"; | ||
} | ||
|
||
csv_file.close(); | ||
std::cout << "Timing results have been written to timing_results.csv" << std::endl; | ||
|
||
return 0; | ||
} |
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,60 @@ | ||
// This program performs some examples of the parallel computations that can be done with the | ||
// LatticeField class. | ||
// As examples, this performs and times: | ||
// - Parallel reduction of the lattice field (values greater than 0.5 only). | ||
|
||
|
||
#include "lattice/LatticeField.h" | ||
#include <complex> | ||
#include <chrono> | ||
#include <iostream> | ||
#include <cmath> | ||
#include <fstream> | ||
#include <vector> | ||
#include <functional> | ||
|
||
int main() { | ||
using namespace std::chrono; | ||
|
||
std::ofstream csv_file("reduce_if_times.csv"); | ||
csv_file << "Parallel_reduce_if [ms],Sequential_reduce_if [ms]\n"; | ||
|
||
for (int i = 0; i < 100; ++i) { | ||
// Create a lattice field of size 8x8x8x8 with initial value 0.0 | ||
LatticeField<double> lattice(8, 8, 8, 8, 0.0); | ||
|
||
// Randomize the lattice field | ||
lattice.randomize(); | ||
|
||
// Perform parallel reduction of the lattice field (values greater than 0.5 only) | ||
const auto start_parallel = high_resolution_clock::now(); | ||
double sum_parallel = lattice.reduce_if( | ||
[](const double& val) { return val > 0.5; }, | ||
0.0, | ||
[](const double& a, const double& b) { return a + b; } | ||
); | ||
const auto end_parallel = high_resolution_clock::now(); | ||
auto timed_parallel_reduce = duration_cast<microseconds>(end_parallel - start_parallel).count(); | ||
|
||
// Randomize the lattice field | ||
lattice.randomize(); | ||
|
||
// Perform sequential reduction of the lattice field (values greater than 0.5 only) | ||
const auto start_sequential = high_resolution_clock::now(); | ||
double sum_sequential = lattice.reduce_if_sequential( | ||
[](const double& val) { return val > 0.5; }, | ||
0.0, | ||
[](const double& a, const double& b) { return a + b; } | ||
); | ||
const auto end_sequential = high_resolution_clock::now(); | ||
auto timed_sequential_reduce = duration_cast<microseconds>(end_sequential - start_sequential).count(); | ||
|
||
// Write the times to the CSV file | ||
csv_file << timed_parallel_reduce << "," << timed_sequential_reduce << "\n"; | ||
} | ||
|
||
csv_file.close(); | ||
std::cout << "Timing results have been written to reduce_if_times.csv" << std::endl; | ||
|
||
return 0; | ||
} |
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,16 +1 @@ | ||
#ifndef GAUGEFIELD_H | ||
#define GAUGEFIELD_H | ||
|
||
#include "lattice/LatticeField.h" // Include the header for LatticeField | ||
|
||
// Define the subclass GaugeField | ||
template <typename T> | ||
class GaugeField : public LatticeField<T> { | ||
public: | ||
GaugeField(int dim1, int dim2, int dim3, int dim4, const T& default_value) | ||
: LatticeField<T>(dim1, dim2, dim3, dim4, default_value) {}; | ||
~GaugeField() = default; | ||
|
||
// Additional methods specific to GaugeField can be added here | ||
T compute_plaquette() const; | ||
}; | ||
// TODO: |
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
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 |
---|---|---|
@@ -1,35 +1 @@ | ||
#include "lattice/LatticeField.h" // Include the header for LatticeField | ||
#include "gauge/GaugeField.h" | ||
#include <numeric> // For std::accumulate | ||
#include <vector> // For std::vector | ||
|
||
// Define the subclass GaugeField | ||
template <typename T> // In here, T would be a length 4 / 8 array of SU(3) matrices. | ||
class GaugeField : public LatticeField { | ||
public: | ||
// Constructor | ||
GaugeField() : LatticeField() {} | ||
|
||
// Function to compute the plaquette | ||
double compute_plaquette(const std::vector<double>& field_values) const{ | ||
// Perform a reduction sum over all the values in the field_values | ||
return std::accumulate(field_values.begin(), field_values.end(), 0.0); | ||
} | ||
}; | ||
|
||
|
||
|
||
#include "GaugeField.h" | ||
|
||
template <typename T> | ||
GaugeField<T>::GaugeField(int dim1, int dim2, int dim3, int dim4) | ||
: LatticeField<T>(dim1, dim2, dim3, dim4) { | ||
// Additional initialization specific to GaugeField can be added here | ||
|
||
} | ||
|
||
// Explicit template instantiation | ||
template class GaugeField<float>; | ||
template class GaugeField<double>; | ||
template class GaugeField<std::complex<float>>; | ||
template class GaugeField<std::complex<double>>; | ||
// TODO: |
Oops, something went wrong.