<?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 mode cannot open file, warnings exist in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/offload-mode-cannot-open-file-warnings-exist/m-p/1055816#M51859</link>
    <description>&lt;P&gt;hi~ all&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I want to use multiple threads to parallelize a for loop. Each iteration opens a file. I use the offload mode, and the compiler reports warning saying&lt;/P&gt;

&lt;P&gt;"warning #2571: variable has not been declared with compatible "target" attribute&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;ifstream fin(my_str.c_str(),ios::in);"&lt;/P&gt;

&lt;P&gt;I ignored the warnings, but the program crashed.&lt;/P&gt;

&lt;P&gt;What can I do to make the codes work? Thanks!&lt;/P&gt;

&lt;P&gt;The compile command is:&lt;/P&gt;

&lt;P&gt;icc -std=c++0x -openmp -O3&amp;nbsp;&lt;/P&gt;

&lt;P&gt;The codes are these:&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()
{
	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";
	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);
	}
	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);
#endif&lt;/PRE&gt;

&lt;P&gt;A.cpp&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "A.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)
{
	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 input_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,input_buffer,'\n'))
		{
			istringstream iss(input_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>Sun, 06 Jul 2014 05:16:46 GMT</pubDate>
    <dc:creator>White_B_</dc:creator>
    <dc:date>2014-07-06T05:16:46Z</dc:date>
    <item>
      <title>offload mode cannot open file, warnings exist</title>
      <link>https://community.intel.com/t5/Software-Archive/offload-mode-cannot-open-file-warnings-exist/m-p/1055816#M51859</link>
      <description>&lt;P&gt;hi~ all&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I want to use multiple threads to parallelize a for loop. Each iteration opens a file. I use the offload mode, and the compiler reports warning saying&lt;/P&gt;

&lt;P&gt;"warning #2571: variable has not been declared with compatible "target" attribute&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;ifstream fin(my_str.c_str(),ios::in);"&lt;/P&gt;

&lt;P&gt;I ignored the warnings, but the program crashed.&lt;/P&gt;

&lt;P&gt;What can I do to make the codes work? Thanks!&lt;/P&gt;

&lt;P&gt;The compile command is:&lt;/P&gt;

&lt;P&gt;icc -std=c++0x -openmp -O3&amp;nbsp;&lt;/P&gt;

&lt;P&gt;The codes are these:&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()
{
	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";
	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);
	}
	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);
#endif&lt;/PRE&gt;

&lt;P&gt;A.cpp&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include "A.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)
{
	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 input_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,input_buffer,'\n'))
		{
			istringstream iss(input_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>Sun, 06 Jul 2014 05:16:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/offload-mode-cannot-open-file-warnings-exist/m-p/1055816#M51859</guid>
      <dc:creator>White_B_</dc:creator>
      <dc:date>2014-07-06T05:16:46Z</dc:date>
    </item>
    <item>
      <title>This appears to be (about)</title>
      <link>https://community.intel.com/t5/Software-Archive/offload-mode-cannot-open-file-warnings-exist/m-p/1055817#M51860</link>
      <description>&lt;P&gt;This appears to be (about) the same program posted in your subsequent post here (https://software.intel.com/en-us/forums/topic/517851) which compiles and runs based on my reply in the other thread, however, it still reports the file opened failed.&lt;/P&gt;

&lt;P&gt;I will look into the open failure a bit more and then post an update in this thread when I know more.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 12:36:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/offload-mode-cannot-open-file-warnings-exist/m-p/1055817#M51860</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2014-07-08T12:36:27Z</dc:date>
    </item>
  </channel>
</rss>

