Software Archive
Read-only legacy content
17061 Discussions

undefined reference to std::sort() in offload on mic

baoyun_p_
Beginner
420 Views

I want to execute std::sort() in offload method on MIC, the code as following:

#include <stdlib.h>
#include <algorithm>
#define data_num 100000
#pragma offload_attribute(push,target(mic)) 
struct T{
	float fea;
	int pos;
} ;
bool myGreater(T i, T j){
	return i.fea > j.fea;
}
T *data;
#pragma offload_attribute(pop) 

void main(){
	#pragma offload target(mic:0) in(data:length(data_num) alloc_if(1))
            {
                data = (T*) malloc(sizeof(T) * data_num);
                ....
		std::sort(data, data+data_num, myGreater);
            }
}

 I use icc compiler to compile, and it give the error informantion: "undefined reference to std::sort<T*, bool(*)>..." , but when I remove the all "#pragma...", it can  go through compile. 

I guess that the std::sort algorithm cannot be used in MIC, 

0 Kudos
1 Solution
Kevin_D_Intel
Employee
420 Views

Encapsulate at least <algorithm> within an offload_attribute push/pop. i.e.

#pragma offload_attribute(push, target(mic))
#include <algorithm>
#pragma offload_attribute(pop)

View solution in original post

0 Kudos
1 Reply
Kevin_D_Intel
Employee
421 Views

Encapsulate at least <algorithm> within an offload_attribute push/pop. i.e.

#pragma offload_attribute(push, target(mic))
#include <algorithm>
#pragma offload_attribute(pop)

0 Kudos
Reply