From edc7689a7fa4caef1b97a6f0b940b98bf6d74f75 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 20 May 2018 08:33:21 -0400 Subject: [PATCH] Fix overcommit resources for Scrypt parallelization (GH #641) --- scrypt.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scrypt.cpp b/scrypt.cpp index 5a53ca1e..3566c3e1 100644 --- a/scrypt.cpp +++ b/scrypt.cpp @@ -245,8 +245,14 @@ size_t Scrypt::DeriveKey(byte*derived, size_t derivedLen, const byte*secret, siz // 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) PBKDF2_SHA256(B, B.size(), secret, secretLen, salt, saltLen, 1); + #ifdef _OPENMP + int threads = STDMIN(omp_get_max_threads(), + static_cast(STDMIN(static_cast(parallel), + static_cast(std::numeric_limits::max())))); + #endif + // http://stackoverflow.com/q/49604260/608639 - #pragma omp parallel + #pragma omp parallel num_threads(threads) { // Each thread gets its own copy AlignedSecByteBlock XY(static_cast(blockSize * 256U));