2

我正在使用英特尔 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)

我读过这个页面。但我想不出如何传输这些数据。我能做些什么?

对不起我糟糕的英语。谢谢你。

4

1 回答 1

0

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

从您链接的文档中:

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

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

于 2015-01-08T12:47:23.760 回答