【问题标题】:Why do I get this error in this omp_declare_reduction?为什么我在这个 omp_declare_reduction 中得到这个错误?
【发布时间】:2017-09-18 21:37:58
【问题描述】:

我有这个文件:

啊.h

struct B;

struct A
{
    A(... B &b) :
        b(b) {}

    B &b;
};

还有B.h

#include "A.h"
struct B{
...
std::vector<A> as;
}

我有这个omp_declare_reduction

#pragma omp declare reduction(merge : B : omp_out.as.insert(omp_out.as.end(), omp_in.as.begin(), omp_in.as.end()))

但是,我收到此错误(A=FindAffineShapeArgsB=Wrapper):

/usr/include/c++/5/bits/stl_algobase.h(564): error: function "FindAffineShapeArgs::operator=(const FindAffineShapeArgs &)" (declared implicitly) cannot be referenced -- it is a deleted function
        *--__result = std::move(*--__last);
                    ^
          detected during:
            instantiation of "_BI2 std::__copy_move_backward<true, false, std::random_access_iterator_tag>::__copy_move_b(_BI1, _BI1, _BI2) [with _BI1=FindAffineShapeArgs *, _BI2=FindAffineShapeArgs *]" at line 606
            instantiation of "_BI2 std::__copy_move_backward_a<_IsMove,_BI1,_BI2>(_BI1, _BI1, _BI2) [with _IsMove=true, _BI1=FindAffineShapeArgs *, _BI2=FindAffineShapeArgs *]" at line 615
            instantiation of "_BI2 std::__copy_move_backward_a2<_IsMove,_BI1,_BI2>(_BI1, _BI1, _BI2) [with _IsMove=true, _BI1=FindAffineShapeArgs *, _BI2=FindAffineShapeArgs *]" at line 686
            instantiation of "_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1=FindAffineShapeArgs *, _BI2=FindAffineShapeArgs *]" at line 636 of "/usr/include/c++/5/bits/vector.tcc"
            instantiation of "void std::vector<_Tp, _Alloc>::_M_range_insert(std::vector<_Tp, _Alloc>::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _Tp=FindAffineShapeArgs, _Alloc=std::allocator<FindAffineShapeArgs>, _ForwardIterator=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>]" at line 1377 of "/usr/include/c++/5/bits/stl_vector.h"
            instantiation of "void std::vector<_Tp, _Alloc>::_M_insert_dispatch(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator, std::__false_type) [with _Tp=FindAffineShapeArgs, _Alloc=std::allocator<FindAffineShapeArgs>, _InputIterator=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>]" at line 1100 of "/usr/include/c++/5/bits/stl_vector.h"
            instantiation of "std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _Tp=FindAffineShapeArgs, _Alloc=std::allocator<FindAffineShapeArgs>, _InputIterator=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>, <unnamed>=void]" at line 345 of
                      "/home/luca/Dropbox/HKUST/CloudCache/cloudcache/CloudCache/Descriptors/hesaff/pyramid.cpp"

    /usr/include/c++/5/bits/stl_algobase.h(340): error: function "FindAffineShapeArgs::operator=(const FindAffineShapeArgs &)" (declared implicitly) cannot be referenced -- it is a deleted function
              *__result = *__first;
                        ^
              detected during:
                instantiation of "_OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II=FindAffineShapeArgs *, _OI=FindAffineShapeArgs *]" at line 402
                instantiation of "_OI std::__copy_move_a<_IsMove,_II,_OI>(_II, _II, _OI) [with _IsMove=false, _II=FindAffineShapeArgs *, _OI=FindAffineShapeArgs *]" at line 440
                instantiation of "_OI std::__copy_move_a2<_IsMove,_II,_OI>(_II, _II, _OI) [with _IsMove=false, _II=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>, _OI=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>]" at line 472
                instantiation of "_OI std::copy(_II, _II, _OI) [with _II=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>, _OI=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>]" at line 637 of "/usr/include/c++/5/bits/vector.tcc"
                instantiation of "void std::vector<_Tp, _Alloc>::_M_range_insert(std::vector<_Tp, _Alloc>::iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _Tp=FindAffineShapeArgs, _Alloc=std::allocator<FindAffineShapeArgs>, _ForwardIterator=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>]" at line 1377 of "/usr/include/c++/5/bits/stl_vector.h"
                instantiation of "void std::vector<_Tp, _Alloc>::_M_insert_dispatch(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator, std::__false_type) [with _Tp=FindAffineShapeArgs, _Alloc=std::allocator<FindAffineShapeArgs>, _InputIterator=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>]" at line 1100 of "/usr/include/c++/5/bits/stl_vector.h"
                instantiation of "std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _Tp=FindAffineShapeArgs, _Alloc=std::allocator<FindAffineShapeArgs>, _InputIterator=__gnu_cxx::__normal_iterator<FindAffineShapeArgs *, std::vector<FindAffineShapeArgs, std::allocator<FindAffineShapeArgs>>>, <unnamed>=void]" at line 345 of
                          "/home/luca/Dropbox/HKUST/CloudCache/cloudcache/CloudCache/Descriptors/hesaff/pyramid.cpp"

    compilation aborted for /home/luca/Dropbox/HKUST/CloudCache/cloudcache/CloudCache/Descriptors/hesaff/pyramid.cpp (code 2)

为什么会这样?这可能与this 有关,但情况不同。

【问题讨论】:

    标签: c++ parallel-processing openmp reduce


    【解决方案1】:

    这与 omp 或明显的循环引用无关(这里的循环引用 per se 没有任何问题)。您将收到类似的编译错误:

    #include <vector>
    
    struct B {};
    
    struct A
    {
        A(B &b) :
            b(b) {}
    
        B &b;
    };
    
    
    B b;
    A a{b}, aa{b};
    
    void foo()
    {
            a=aa;
    }
    

    gcc 错误的消息,在这种情况下,会给你指出线索:

    t.C:19:4: error: use of deleted function ‘A& A::operator=(const A&)’
    

    包含引用的类没有默认赋值运算符。这是因为引用不能在传统意义上被更改或“分配给”。

    您正在创建一个std::vector,它需要根据需要复制/移动其值。但是向量的类包含一个引用成员,它将类的赋值运算符从高轨道上删除。

    为了实现这一点,您需要为A 类定义自己的赋值运算符和/或复制构造函数,并让它们执行您需要它们执行的操作。

    【讨论】:

    • 那么我需要做的是创建一个复制构造函数 A(... const B &amp;b) : ,对吧?这很痛苦,因为我需要在A 中修改b...
    • @justHelloWorld 你可以存储一些可分配的东西,比如指针。
    • @SamVarshavchik 你能看看this的问题吗?
    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多