提交 848dce85 编写于 作者: H Haipeng Wang

fix #pragma omp problem in clang-format

上级 51f70c41
...@@ -15,12 +15,12 @@ limitations under the License. */ ...@@ -15,12 +15,12 @@ limitations under the License. */
#ifdef PADDLE_MOBILE_USE_OPENMP #ifdef PADDLE_MOBILE_USE_OPENMP
/** /**
* android-ndk-r17 has a problem when linking with openmp. * android-ndk-r17 has a problem when linking with openmp.
* if paddle-mobile enables -fopenmp, but didn't use those omp_* functions, after * if paddle-mobile enables -fopenmp, but didn't use those omp_* functions,
* linking another binary with libpaddle-mobile.so, the omp_get_thread_num will not work. * after linking another binary with libpaddle-mobile.so, the omp_get_thread_num
* see test/common/test_openmp.cc * will not work. see test/common/test_openmp.cc the detailed reason is still
* the detailed reason is still unclear, but this trick will work. * unclear, but this trick will work. a better solution is hacking the linker,
* a better solution is hacking the linker, try some flags to make it link omp_* functions, * try some flags to make it link omp_* functions, but I didn't find out how to
* but I didn't find out how to make it work. * make it work.
*/ */
#include <omp.h> #include <omp.h>
static int _ = omp_get_num_procs(); static int _ = omp_get_num_procs();
......
...@@ -59,7 +59,7 @@ class PoolFunctor<CPU, PoolProcess, T> { ...@@ -59,7 +59,7 @@ class PoolFunctor<CPU, PoolProcess, T> {
T *output_data = output->mutable_data<T>(); T *output_data = output->mutable_data<T>();
for (int i = 0; i < batch_size; i++) { for (int i = 0; i < batch_size; i++) {
#pragma omp parallel for #pragma omp parallel for
for (int c = 0; c < output_channels; ++c) { for (int c = 0; c < output_channels; ++c) {
for (int ph = 0; ph < output_height; ++ph) { for (int ph = 0; ph < output_height; ++ph) {
int hstart = ph * stride_height - padding_height; int hstart = ph * stride_height - padding_height;
......
#include <iostream>
#include <omp.h>
int main(void) {
#pragma omp parallel num_threads(2)
{
int thread_id = omp_get_thread_num();
int nthreads = omp_get_num_threads();
std::cout << "Hello, OMP " << thread_id << "/" << nthreads << "\n";
}
return 0;
}
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed 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 <omp.h>
#include <iostream>
int main(void) {
#pragma omp parallel num_threads(2)
{
int thread_id = omp_get_thread_num();
int nthreads = omp_get_num_threads();
std::cout << "Hello, OMP " << thread_id << "/" << nthreads << "\n";
}
return 0;
}
...@@ -12,4 +12,8 @@ if ! [[ $version == *"$VERSION"* ]]; then ...@@ -12,4 +12,8 @@ if ! [[ $version == *"$VERSION"* ]]; then
exit -1 exit -1
fi fi
clang-format $@ # https://medicineyeh.wordpress.com/2017/07/13/clang-format-with-pragma/
shift
perl -i -pe 's|#pragma\s+omp|// <TRICKY-CLANG-FORMAT-PRAGMA-FIX> #pragma omp|' "$@"
clang-format -i $@
perl -i -pe 's|// <TRICKY-CLANG-FORMAT-PRAGMA-FIX> ||' "$@"
...@@ -7,7 +7,7 @@ EXE_FILE="../../test/build/*" ...@@ -7,7 +7,7 @@ EXE_FILE="../../test/build/*"
EXE_DIR="data/local/tmp/bin" EXE_DIR="data/local/tmp/bin"
MODELS_DIR="data/local/tmp/models" MODELS_DIR="data/local/tmp/models"
IMAGES_DIR="data/local/tmp/images" IMAGES_DIR="data/local/tmp/images"
LIB_PATH="../build/release/arm-v7a/build/*" LIB_PATH="../../build/release/arm-v7a/build/*"
adb push ${EXE_FILE} ${EXE_DIR} adb push ${EXE_FILE} ${EXE_DIR}
adb push ${LIB_PATH} ${EXE_DIR} adb push ${LIB_PATH} ${EXE_DIR}
adb push ${IMAGE_PATH} ${IMAGES_DIR} adb push ${IMAGE_PATH} ${IMAGES_DIR}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册