Hi~ all,
I met some problems when I transform my codes from non-offload mode to offload mode.
The command I used to compile the codes is: icc -std=c++0x
-openmp -O3 -vec-report=3
The compiler I used is icc. I included <omp.h> in multiple header files. If I don't use the offload mode, the program works well. When I add some "#pragma offload target(mic)" directives, the compiler reports error: function "dtime" called in offload region must have been declared with compatible "target" attribute.
Then I tried adding __attribute__((target(mic))) in the header file between the return type and function name. This time, the compiler reports: error: expected a ")" and warning: declaration does not declare anything
How to deal with this problem?
Thanks!
Four files in total:
Main.h
#ifndef MAIN_H #define MAIN_H #include "A.h" #include <omp.h> #include <sys/time.h> using namespace std; static double __attribute__(((target(mic))) dtime() //static double dtime() { double tseconds = 0; struct timeval mytime; gettimeofday(&mytime,(struct timezone*)0); tseconds = (double)(mytime.tv_sec+(double)mytime.tv_usec*1e-6); return tseconds; } #endif
Main.cpp
#include "main.h" using namespace std; int main() { cout << "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<N_total; index_counter++) { if (index_counter==0) printf("\n%d threads.\n", numthreads); vector< vector<int> > my_vec_vec; vector<int> my_vec; set<int> my_set; unordered_map<int,int> 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; }
A.h
#ifndef A_H #define A_H #include <omp.h> #include <iostream> #include <map> #include <set> #include <stdlib.h> #include <string> #include <time.h> #include <unordered_map> #include <vector> using namespace std; void __attribute__(((target(mic))) A_func_1(string my_str, vector<vector<int> >& my_vec_vec, set<int>& my_set, unordered_map<int,int>& my_u_map); void __attribute__(((target(mic))) A_func_2(vector<vector<int> >& my_vec_vec, unordered_map<int,int>& my_u_map, int my_int=0); //void A_func_1(string my_str, vector<vector<int> >& my_vec_vec, set<int>& my_set, unordered_map<int,int>& my_u_map); //void A_func_2(vector<vector<int> >& my_vec_vec, unordered_map<int,int>& my_u_map, int my_int=0); #endif
A.cpp
#include "A.h" using namespace std; void A_func_1(string my_str, vector<vector<int> >& my_vec_vec, set<int>& my_set, unordered_map<int,int>& my_u_map) { srand(time(NULL)); int n_length = rand()%10+1; for (int i=0; i<n_length ;i++) { vector<int> temp_vec; int m_length = rand()%10+1; for (int j=0; j<m_length; j++) temp_vec.push_back(rand()%20); my_vec_vec.push_back(temp_vec); } } void A_func_2(vector<vector<int> >& my_vec_vec, unordered_map<int,int>& my_u_map, int my_int) { int n = my_vec_vec.size(); for (int i=0; i<n; i++) for (int j=0; j<my_vec_vec[i].size(); j++) my_vec_vec[i][j] = j; }