This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent after-fork number of OMP threads being bigger than 1. (#16999)
* Prevent after-fork number of OMP threads being bigger than 1. This could happen if it was set in the environment. As we are setting engine::OpenMP::Get()->set_enabled(false) in initialize.cc in the child after forking, the behaviour goes back to what it was before #15762 was introduced. Regions using omp get the threads count from GetRecommendedOMPThreadCount, so if omp is disabled they will get 1 thread and run serially * add C++ unit test * Add comment
- Loading branch information
1 parent
c82af38
commit 04ebe45
Showing
3 changed files
with
97 additions
and
4 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
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,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "../include/test_util.h" | ||
#include "../../src/engine/openmp.h" | ||
|
||
#if defined(unix) || defined(__unix__) || defined(__unix) | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <dmlc/logging.h> | ||
|
||
|
||
TEST(OMPBehaviour, after_fork) { | ||
/* | ||
* Check that after fork, OMP is disabled, and the recommended thread count is 1 to prevent | ||
* process fanout. | ||
*/ | ||
using namespace mxnet::engine; | ||
auto openmp = OpenMP::Get(); | ||
pid_t pid = fork(); | ||
if (pid == 0) { | ||
EXPECT_FALSE(openmp->enabled()); | ||
EXPECT_EQ(openmp->GetRecommendedOMPThreadCount(), 1); | ||
} else if (pid > 0) { | ||
int status; | ||
int ret = waitpid(pid, &status, 0); | ||
CHECK_EQ(ret, pid) << "waitpid failed"; | ||
} else { | ||
CHECK(false) << "fork failed"; | ||
} | ||
} | ||
#endif |
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