2

I am using Intel C++ Compiler v14.0.3. This following code troubles me:

#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;
}

Compiler gives this message:

$ 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)

I've read this page. But I could not think of how to transfer this data. What can I do?

Sorry for my poor english. Thank you.

1 Answers1

0

I could not think of how to transfer this data. What can I do?

From the document you linked:

"If the data exchanged between CPU and coprocessor is more complex than simple scalars and bit-wise copyable arrays, you may consider using the _Cilk_shared/_Cilk_offload constructs."

#pragma offload will not work because std::map is too complex to be bitwise copyable.

Bulletmagnet
  • 5,665
  • 2
  • 26
  • 56