Skip to content

Commit 5d7ca7b

Browse files
committed
Use OpenMP to parallelize day 22
1 parent c729331 commit 5d7ca7b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

day22/experiments/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# We need Homebrew LLVM since Apple Clang doesn't support OpenMP
2+
CXX=/opt/homebrew/opt/llvm/bin/clang++
3+
14
.PHONY: all
25
all: out/day22
36

47
out:
58
mkdir -p $@
69

710
out/day22: ./day22.cpp | out
8-
$(CXX) $< -Ofast -std=c++11 -o $@
11+
$(CXX) $< -ffast-math -fopenmp -O3 -std=c++11 -o $@

day22/experiments/day22.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int score(std::vector<int> input, int x1, int x2, int x3, int x4) {
5454
int findBestScore(std::vector<int> input) {
5555
int bestScore = 0;
5656
int bound = 9;
57+
#pragma omp parallel for
5758
for (int x1 = -bound; x1 <= bound; x1++) {
5859
for (int x2 = -bound; x2 <= bound; x2++) {
5960
std::cout << "Searching (" << x1 << ", " << x2 << ")" << std::endl;

0 commit comments

Comments
 (0)