小编Sco*_*gan的帖子

openMP嵌套并行for循环vs内部并行for

如果我像这样使用嵌套并行for循环:

#pragma omp parallel for schedule(dynamic,1)
for (int x = 0; x < x_max; ++x) {
    #pragma omp parallel for schedule(dynamic,1)
    for (int y = 0; y < y_max; ++y) { 
    //parallelize this code here
   }
//IMPORTANT: no code in here
}
Run Code Online (Sandbox Code Playgroud)

这相当于:

for (int x = 0; x < x_max; ++x) {
    #pragma omp parallel for schedule(dynamic,1)
    for (int y = 0; y < y_max; ++y) { 
    //parallelize this code here
   }
//IMPORTANT: no code in here
}
Run Code Online (Sandbox Code Playgroud)

除了创建新任务之外,做外部并行吗?

c++ parallel-processing openmp

23
推荐指数
2
解决办法
5万
查看次数

对作为函数参数传递的指针使用delete

删除已作为函数参数传递的指针(如下所示)是否合法(和合法):

#include<iostream>

class test_class{
public:
    test_class():h(9){}
    int h;
    ~test_class(){std::cout<<"deleted";}
};

void delete_test(test_class* pointer_2){
    delete pointer_2;
}

int main(){
    test_class* pointer_1;

    while(true){
        pointer_1 = new test_class;

        //std::cout<<pointer_1->h;

        delete_test(pointer_1);
    }
}
Run Code Online (Sandbox Code Playgroud)

这个编译好了,但我只是想确保它永远都是那样.

c++ memory-management new-operator

9
推荐指数
3
解决办法
1万
查看次数