<TiXmlDocument>在此卸载区域中使用的 map<shared_ptr、double> 不可按位复制

map<shared_ptr<TiXmlDocument>, double> used in this offload region is not bitwise copyable

本文关键字:lt gt ptr double 复制 shared 卸载 TiXmlDocument 卸载区 区域 map      更新时间:2023-10-16

我正在使用英特尔C++编译器 v14.0.3。下面的代码困扰着我:

#include <tinyxml/tinyxml.h>
#include <memory>
#include <map>
#include "offload.h"
using namespace std;
typedef map<shared_ptr<TiXmlDocument>, double,
        less<shared_ptr<TiXmlDocument> >,
        __offload::shared_allocator<pair<shared_ptr<TiXmlDocument>, double> > > xmlanddbl;
__declspec(target(mic)) _Cilk_shared xmlanddbl m;
int main(void)
{
  const int maxct = 10;
  for(int i = 0; i < 10; i++){
    shared_ptr<TiXmlDocument> doc(new TiXmlDocument);
    if(doc && doc->LoadFile("something.xml")){
      m.insert(make_pair(doc, 0.0));
    }
  }
  for(int ct = 0; ct < maxct; ct++){
#pragma offload target(mic) mandatory
#pragma omp parallel
#pragma omp single
    {
      for(auto it = m.begin(); it != m.end(); it++){
#pragma omp task firstprivate(it)
        {
          someclass obj(it->first);
          it->second = obj.eval();
        }
      }
#pragma omp taskwait
    }
    somefunction(m);
  }
  return 0;
}

编译器给出以下消息:

$ icpc -c thiscode.cpp -O2 -openmp -parallel -std=c++11 -I./include
thiscode.cpp(24): error: variable "m" used in this offload region is not bitwise copyable
  #pragma offload target(mic) mandatory
  ^
compilation aborted for thiscode.cpp (code 2)

我已经阅读了此页面。但是我想不出如何传输这些数据。我能做什么?

对不起,我的英语不好。谢谢。

我想不出如何传输这些数据。我能做什么?

从您链接的文档中:

"如果CPU和协处理器之间交换的数据比简单的标量和按位可复制数组更复杂,则可以考虑使用_Cilk_shared/_Cilk_offload结构。

#pragma offload将不起作用,因为 std::map 太复杂而无法按位复制。