<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic offload error, dlopen() failed in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056984#M52453</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I run my program on MIC by the offload mode. However, it returns error:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
	&lt;P&gt;/var/volatile/tmp/coi_procs/1/29947/load_lib/iccout4vLAcb: undefined symbol: _ZNSt3setIiSt4lessIiESaIiEED1Ev&lt;BR /&gt;
		offload error: cannot load library to the device 0 (error code 20)On the sink, dlopen() returned NULL. The result of dlerror() is "/var/volatile/tmp/coi_procs/1/29947/load_lb/iccout4vLAcb: undefined symbol: _ZNSt3setIiSt4lessIiESaIiEED1Ev"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The native mode works fine. Could anyone please tell me how to figure out this problem? Thanks!&lt;/P&gt;

&lt;P&gt;The function of the program is to read numbers from a *.txt file into a vector and an ordered_map&lt;/P&gt;

&lt;P&gt;The compile command I used is:&lt;/P&gt;

&lt;P&gt;icc -openmp -std=c++0x -O main main.cpp A.cpp&lt;/P&gt;

&lt;P&gt;The following are the codes:&lt;/P&gt;

&lt;P&gt;main.h&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#ifndef MAIN_H
#define MAIN_H
#include "A.h"
#include &amp;lt;omp.h&amp;gt;
#include &amp;lt;sys/time.h&amp;gt;

using namespace std;

__attribute__((target(mic))) static double dtime()
//static double dtime()
{
	double tseconds = 0;
	struct timeval mytime;
	gettimeofday(&amp;amp;mytime,(struct timezone*)0);
	tseconds = (double)(mytime.tv_sec+(double)mytime.tv_usec*1e-6);
	return tseconds;
}
#endif
&lt;/PRE&gt;

&lt;P&gt;main.cpp&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "main.h"

using namespace std;

int main()
{
	cout &amp;lt;&amp;lt; "Start.\n";
	//string my_str = "content_string";
	int N_total = 10, index_counter = 0, numthreads = 0;
	double t_begin = dtime(), t_end;
#pragma offload target (mic)
#pragma omp parallel
#pragma omp master
	numthreads = omp_get_num_threads();
	printf("Initializing.. %d Threads",numthreads);

#pragma offload target(mic)
#pragma omp  parallel for private (index_counter)
	for (index_counter=0; index_counter&amp;lt;N_total; index_counter++)
	{
		if (index_counter==0)
			printf("\n%d threads.\n", numthreads);
		string my_str = "content_string";
		vector&amp;lt; vector&amp;lt;int&amp;gt; &amp;gt; my_vec_vec;
		vector&amp;lt;int&amp;gt; my_vec;
		set&amp;lt;int&amp;gt; my_set;
		unordered_map&amp;lt;int,int&amp;gt; my_u_map;
		int my_int = 1;	
		double t_i_start=dtime(), t_i_end;
		A_func_1(my_str,my_vec_vec,my_set,my_u_map);
		
		t_i_end = dtime();
		//A_func_2(my_vec_vec,my_u_map,my_int);
		printf("time: %9.5lf\n",(t_i_end-t_i_start));
	}
	
	return 0;
}
&lt;/PRE&gt;

&lt;P&gt;A.h&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#ifndef A_H
#define A_H
#include &amp;lt;omp.h&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;map&amp;gt;
#include &amp;lt;set&amp;gt;
#include &amp;lt;sstream&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;time.h&amp;gt;
#include &amp;lt;unordered_map&amp;gt;
#include &amp;lt;vector&amp;gt;


using namespace std;

 __attribute__((target(mic))) void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_set, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map);
 __attribute__((target(mic))) void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map, int my_int=0);
//void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_set, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map);
//void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map, int my_int=0);

#endif
&lt;/PRE&gt;

&lt;P&gt;A.cpp&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "A.h"
#include "stdio.h"
#include "string.h"

using namespace std;

void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_set, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map)
{
	FILE *pFILE = fopen(my_str.c_str(),"r"); 
	string string_buffer;

	char *input_buffer_char=NULL; size_t i_b_c_length;
	char const_char_buffer_comma[40960] = "";
	char char_buffer_comma;
	
	int int_buffer, count_buffer;
	vector&amp;lt;int&amp;gt; vec_buffer;
	unordered_map&amp;lt;int,int&amp;gt;::iterator key_pos;
	if (pFILE==NULL)
		printf("%s open fail!\n",my_str.c_str());
	else
	{
		while (getline(&amp;amp;input_buffer_char,&amp;amp;i_b_c_length,pFILE)!=-1)
		{
			strcpy(const_char_buffer_comma,input_buffer_char);
			string_buffer = string(const_char_buffer_comma);
			istringstream iss(string_buffer);	// each line, each transaction
			while (iss&amp;gt;&amp;gt;int_buffer)
			{
				vec_buffer.push_back(int_buffer); //my_set.insert(int_buffer);
				key_pos = my_u_map.find(int_buffer);
				if (key_pos!=my_u_map.end())
				{
					count_buffer = key_pos-&amp;gt;second;
					my_u_map.erase(key_pos);
					my_u_map.insert(pair&amp;lt;int,int&amp;gt;(int_buffer,count_buffer+1));
				}
				else
				{
					my_u_map.insert(pair&amp;lt;int,int&amp;gt;(int_buffer,1));
				}
				iss &amp;gt;&amp;gt; char_buffer_comma; // eliminate the ","
			}
			my_vec_vec.push_back(vec_buffer);	// one transaction push_backed into transaction set
			vec_buffer.clear();
		}
		fclose(pFILE);
	}
/*
	srand(time(NULL));
	int n_length = rand()%10+1;
	for (int i=0; i&amp;lt;n_length ;i++)
	{
		vector&amp;lt;int&amp;gt; temp_vec;
		int m_length = rand()%10+1;
		for (int j=0; j&amp;lt;m_length; j++)
			temp_vec.push_back(rand()%20);
		my_vec_vec.push_back(temp_vec);
	}
	string string_buffer;
	int int_buffer;
	ifstream fin(my_str.c_str(),ios::in);
	if (!fin.is_open())
		printf("file open error.\n");
	else
	{
		while (getline(fin,string_buffer,'\n'))
		{
			istringstream iss(string_buffer);
			while (iss&amp;gt;&amp;gt;int_buffer)
			{
				my_set.insert(int_buffer);
			}
		}
	}
*/
}
void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map, int my_int)
{
	int n = my_vec_vec.size();
	for (int i=0; i&amp;lt;n; i++)
		for (int j=0; j&amp;lt;my_vec_vec&lt;I&gt;.size(); j++)
			my_vec_vec&lt;I&gt;&lt;J&gt; = j;
}
&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jul 2014 01:53:15 GMT</pubDate>
    <dc:creator>White_B_</dc:creator>
    <dc:date>2014-07-08T01:53:15Z</dc:date>
    <item>
      <title>offload error, dlopen() failed</title>
      <link>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056984#M52453</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I run my program on MIC by the offload mode. However, it returns error:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
	&lt;P&gt;/var/volatile/tmp/coi_procs/1/29947/load_lib/iccout4vLAcb: undefined symbol: _ZNSt3setIiSt4lessIiESaIiEED1Ev&lt;BR /&gt;
		offload error: cannot load library to the device 0 (error code 20)On the sink, dlopen() returned NULL. The result of dlerror() is "/var/volatile/tmp/coi_procs/1/29947/load_lb/iccout4vLAcb: undefined symbol: _ZNSt3setIiSt4lessIiESaIiEED1Ev"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The native mode works fine. Could anyone please tell me how to figure out this problem? Thanks!&lt;/P&gt;

&lt;P&gt;The function of the program is to read numbers from a *.txt file into a vector and an ordered_map&lt;/P&gt;

&lt;P&gt;The compile command I used is:&lt;/P&gt;

&lt;P&gt;icc -openmp -std=c++0x -O main main.cpp A.cpp&lt;/P&gt;

&lt;P&gt;The following are the codes:&lt;/P&gt;

&lt;P&gt;main.h&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#ifndef MAIN_H
#define MAIN_H
#include "A.h"
#include &amp;lt;omp.h&amp;gt;
#include &amp;lt;sys/time.h&amp;gt;

using namespace std;

__attribute__((target(mic))) static double dtime()
//static double dtime()
{
	double tseconds = 0;
	struct timeval mytime;
	gettimeofday(&amp;amp;mytime,(struct timezone*)0);
	tseconds = (double)(mytime.tv_sec+(double)mytime.tv_usec*1e-6);
	return tseconds;
}
#endif
&lt;/PRE&gt;

&lt;P&gt;main.cpp&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "main.h"

using namespace std;

int main()
{
	cout &amp;lt;&amp;lt; "Start.\n";
	//string my_str = "content_string";
	int N_total = 10, index_counter = 0, numthreads = 0;
	double t_begin = dtime(), t_end;
#pragma offload target (mic)
#pragma omp parallel
#pragma omp master
	numthreads = omp_get_num_threads();
	printf("Initializing.. %d Threads",numthreads);

#pragma offload target(mic)
#pragma omp  parallel for private (index_counter)
	for (index_counter=0; index_counter&amp;lt;N_total; index_counter++)
	{
		if (index_counter==0)
			printf("\n%d threads.\n", numthreads);
		string my_str = "content_string";
		vector&amp;lt; vector&amp;lt;int&amp;gt; &amp;gt; my_vec_vec;
		vector&amp;lt;int&amp;gt; my_vec;
		set&amp;lt;int&amp;gt; my_set;
		unordered_map&amp;lt;int,int&amp;gt; my_u_map;
		int my_int = 1;	
		double t_i_start=dtime(), t_i_end;
		A_func_1(my_str,my_vec_vec,my_set,my_u_map);
		
		t_i_end = dtime();
		//A_func_2(my_vec_vec,my_u_map,my_int);
		printf("time: %9.5lf\n",(t_i_end-t_i_start));
	}
	
	return 0;
}
&lt;/PRE&gt;

&lt;P&gt;A.h&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#ifndef A_H
#define A_H
#include &amp;lt;omp.h&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;map&amp;gt;
#include &amp;lt;set&amp;gt;
#include &amp;lt;sstream&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;time.h&amp;gt;
#include &amp;lt;unordered_map&amp;gt;
#include &amp;lt;vector&amp;gt;


using namespace std;

 __attribute__((target(mic))) void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_set, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map);
 __attribute__((target(mic))) void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map, int my_int=0);
//void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_set, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map);
//void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map, int my_int=0);

#endif
&lt;/PRE&gt;

&lt;P&gt;A.cpp&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "A.h"
#include "stdio.h"
#include "string.h"

using namespace std;

void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_set, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map)
{
	FILE *pFILE = fopen(my_str.c_str(),"r"); 
	string string_buffer;

	char *input_buffer_char=NULL; size_t i_b_c_length;
	char const_char_buffer_comma[40960] = "";
	char char_buffer_comma;
	
	int int_buffer, count_buffer;
	vector&amp;lt;int&amp;gt; vec_buffer;
	unordered_map&amp;lt;int,int&amp;gt;::iterator key_pos;
	if (pFILE==NULL)
		printf("%s open fail!\n",my_str.c_str());
	else
	{
		while (getline(&amp;amp;input_buffer_char,&amp;amp;i_b_c_length,pFILE)!=-1)
		{
			strcpy(const_char_buffer_comma,input_buffer_char);
			string_buffer = string(const_char_buffer_comma);
			istringstream iss(string_buffer);	// each line, each transaction
			while (iss&amp;gt;&amp;gt;int_buffer)
			{
				vec_buffer.push_back(int_buffer); //my_set.insert(int_buffer);
				key_pos = my_u_map.find(int_buffer);
				if (key_pos!=my_u_map.end())
				{
					count_buffer = key_pos-&amp;gt;second;
					my_u_map.erase(key_pos);
					my_u_map.insert(pair&amp;lt;int,int&amp;gt;(int_buffer,count_buffer+1));
				}
				else
				{
					my_u_map.insert(pair&amp;lt;int,int&amp;gt;(int_buffer,1));
				}
				iss &amp;gt;&amp;gt; char_buffer_comma; // eliminate the ","
			}
			my_vec_vec.push_back(vec_buffer);	// one transaction push_backed into transaction set
			vec_buffer.clear();
		}
		fclose(pFILE);
	}
/*
	srand(time(NULL));
	int n_length = rand()%10+1;
	for (int i=0; i&amp;lt;n_length ;i++)
	{
		vector&amp;lt;int&amp;gt; temp_vec;
		int m_length = rand()%10+1;
		for (int j=0; j&amp;lt;m_length; j++)
			temp_vec.push_back(rand()%20);
		my_vec_vec.push_back(temp_vec);
	}
	string string_buffer;
	int int_buffer;
	ifstream fin(my_str.c_str(),ios::in);
	if (!fin.is_open())
		printf("file open error.\n");
	else
	{
		while (getline(fin,string_buffer,'\n'))
		{
			istringstream iss(string_buffer);
			while (iss&amp;gt;&amp;gt;int_buffer)
			{
				my_set.insert(int_buffer);
			}
		}
	}
*/
}
void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map, int my_int)
{
	int n = my_vec_vec.size();
	for (int i=0; i&amp;lt;n; i++)
		for (int j=0; j&amp;lt;my_vec_vec&lt;I&gt;.size(); j++)
			my_vec_vec&lt;I&gt;&lt;J&gt; = j;
}
&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 01:53:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056984#M52453</guid>
      <dc:creator>White_B_</dc:creator>
      <dc:date>2014-07-08T01:53:15Z</dc:date>
    </item>
    <item>
      <title>Maybe the font of the error</title>
      <link>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056985#M52454</link>
      <description>&lt;P&gt;Maybe the font of the error is unreadable. Here is another font:&lt;/P&gt;

&lt;P&gt;On the remote process, dlopen() failed. The error message sent back from the sink is /var/volatile/tmp/coi_procs/1/29947/load_lib/iccout4vLAcb: undefined symbol: _ZNSt3setIiSt4lessIiESaIiEED1Ev&lt;BR /&gt;
	offload error: cannot load library to the device 0 (error code 20)On the sink, dlopen() returned NULL. The result of dlerror() is "/var/volatile/tmp/coi_procs/1/29947/load_lb/iccout4vLAcb: undefined symbol: _ZNSt3setIiSt4lessIiESaIiEED1Ev"&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 01:55:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056985#M52454</guid>
      <dc:creator>White_B_</dc:creator>
      <dc:date>2014-07-08T01:55:13Z</dc:date>
    </item>
    <item>
      <title>The offload code requires</title>
      <link>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056986#M52455</link>
      <description>&lt;P&gt;The offload code/compilation requires content from various includes inside A.h. Wrapper those includes with &lt;STRONG&gt;offload_attribute push/pop&lt;/STRONG&gt; as shown:&lt;/P&gt;

&lt;P&gt;A.h:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#ifndef A_H
#define A_H
#pragma offload_attribute (push, target (mic))
#include &amp;lt;omp.h&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;map&amp;gt;
#include &amp;lt;set&amp;gt;
#include &amp;lt;sstream&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;time.h&amp;gt;
#include &amp;lt;unordered_map&amp;gt;
#include &amp;lt;vector&amp;gt;
#pragma offload_attribute (pop)


using namespace std;

 __attribute__((target(mic))) void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp;
 my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_set, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map);
 __attribute__((target(mic))) void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, un
ordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map, int my_int=0);
//void A_func_1(string my_str, vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, set&amp;lt;int&amp;gt;&amp;amp; my_se
t, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_map);
//void A_func_2(vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt;&amp;amp; my_vec_vec, unordered_map&amp;lt;int,int&amp;gt;&amp;amp; my_u_m
ap, int my_int=0);

#endif&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 09:35:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056986#M52455</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2014-07-08T09:35:00Z</dc:date>
    </item>
    <item>
      <title>Thanks! It works.</title>
      <link>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056987#M52456</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 15:16:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/offload-error-dlopen-failed/m-p/1056987#M52456</guid>
      <dc:creator>White_B_</dc:creator>
      <dc:date>2014-07-08T15:16:00Z</dc:date>
    </item>
  </channel>
</rss>

