Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ggml/src/ggml-cpu/ggml-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3563,13 +3563,17 @@ void ggml_cpu_init(void) {
#ifdef GGML_USE_OPENMP
//if (!getenv("OMP_WAIT_POLICY")) {
// // set the wait policy to active, so that OpenMP threads don't sleep
// putenv("OMP_WAIT_POLICY=active");
// setenv("OMP_WAIT_POLICY", "active", 0)
//}

if (!getenv("KMP_BLOCKTIME")) {
// set the time to wait before sleeping a thread
// this is less aggressive than setting the wait policy to active, but should achieve similar results in most cases
putenv("KMP_BLOCKTIME=200"); // 200ms
#ifdef _WIN32
_putenv_s("KMP_BLOCKTIME", "200"); // 200ms
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 We couldn't use setenv on Windows. So I decided to use _putenv_s instead.

D:/a/llama.cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3572:17: error: implicit declaration of function 'setenv'; did you mean 'getenv'? [-Wimplicit-function-declaration]
 3572 |                 setenv("KMP_BLOCKTIME", "200", 0); // 200ms
      |                 ^~~~~~
      |                 getenv

ref: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/putenv-s-wputenv-s

#else
setenv("KMP_BLOCKTIME", "200", 0); // 200ms
#endif
}
#endif
}
Expand Down
Loading