- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, when I try to compile the below code I get a warning that data is not a pointer to shared data how do I declare data such that it is shared and these warnings do not appear during compilation.
Here is the code:
[cpp]
#include "myFunc.h"
#include "myGauss.h"
#include "myExp.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <cilk/cilk.h>
#include <offload.h>
_Cilk_shared myGauss gauss;
_Cilk_shared int length = 1000000;
double * _Cilk_shared data;
_Cilk_shared int threads;
int main(){
double sigma = 0.783;
int scanNumber = 1000;
data = (double * _Cilk_shared) _Offload_shared_malloc(sizeof(double)*length);
// funcp = (_Cilk_shared myFunc *) new myGauss(sigma);
gauss = myGauss(sigma);
// funcp->generateData(length,data);
_Cilk_offload gauss.generateData(length,data);
printf("Finished generating data\n");
double * NLLS = (double * ) malloc(sizeof(double)*scanNumber);
FILE * output = fopen("offloaded.dat","w");
for(threads=244; threads<250; threads+=10){
double time = omp_get_wtime();
for(int i=0 ; i<scanNumber; i++){
double sigmaGuess = i*0.001+0.001;
// funcp->setParameter(sigmaGuess);
gauss.setParameter(sigmaGuess);
//Calculating the negative loglikeliHood
NLLS = _Cilk_offload gauss.evaluate(data,length,threads);
//NLLS= funcp->evaluate(data,length);
// printf("%d %% done \n",i);
}
//Finding the minimum on the host
int minIndex = INT_MAX;
double minValue = DBL_MAX;
for(int i=0; i<scanNumber; i++){
if(NLLS<minValue){
minValue = NLLS;
minIndex = i;
}
}
double minSig = minIndex*0.001+0.001;
time = omp_get_wtime()-time;
printf("Sigma val %f\n",minSig);
fprintf(output,"%d %f\n",threads,time);
}
fclose(output);
return 0;
}
[/cpp]
Here are the warnings I get on compilation:
[plain]
main.cpp(26): warning #2707: pointer argument in _Cilk_offload function call is not pointer-to-shared
_Cilk_offload gauss.generateData(length,data);
main.cpp(37): warning #2707: pointer argument in _Cilk_offload function call is not pointer-to-shared
NLLS = _Cilk_offload gauss.evaluate(data,length,threads);
[/plain]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There have been a couple of erroneous cases of this warning in the past. I need to check about your case.
Is it possible to get complete compile-able test case? We need insight into mygauss.h and perhaps myFunc.h, myExp.h also.
You may need to declare data as: _Cilk_shared double * data;
For pointer to shared double if that is the interest and adjust the _Offload_shared_malloc() call too.
I'll post again soon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Development advised that with your original declaration "data was a shared pointer to non-shared data" and that you may need to declare data as I indicated earlier or possibly as:
_Cilk_shared double * _Cilk_shared data; // (i.e. make both the pointer and what it is pointing to as shared)
We would know better about the warning having the complete reproducer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here are the rest of the source files
myFunc.h
[cpp]
#include <cilk/cilk.h>
#ifndef MYFUNC_H
#define MYFUNC_H
#pragma offload_attribute(push,_Cilk_shared)
class myFunc{
protected:
double paramValue;
public:
myFunc() {paramValue = 1; };
myFunc(double param){
paramValue = param;
};
~myFunc(){};
virtual void generateData(int outputLength,double * p)=0;
virtual double evaluate(double * dataSet, int dataLength, int threads)=0;
virtual void setParameter(double para){paramValue = para;};
virtual double getParameter(){return paramValue;};
virtual double normValue()=0;
};
#pragma offload_attribute(pop)
#endif
[/cpp]
myGauss.h
#include <cilk/cilk.h>
#ifndef MYFUNC_H
#define MYFUNC_H
#pragma offload_attribute(push,_Cilk_shared)
class myFunc{
protected:
double paramValue;
public:
myFunc() {paramValue = 1; };
myFunc(double param){
paramValue = param;
};
~myFunc(){};
virtual void generateData(int outputLength,double * p)=0;
virtual double evaluate(double * dataSet, int dataLength, int threads)=0;
virtual void setParameter(double para){paramValue = para;};
virtual double getParameter(){return paramValue;};
virtual double normValue()=0;
};
#pragma offload_attribute(pop)
#endif
[cpp]
#include "myFunc.h"
#include <cilk/cilk.h>
#ifndef MYGAUSS_H
#define MYGAUSS_H
#pragma offload_attribute(push,_Cilk_shared)
class myGauss: public myFunc {
private:
double oneOverTwoSigSq;
double sqrtTwoPi;
public:
myGauss(double sigma);
myGauss();
~myGauss();
double getParameter();
void setParameter(double newSigma);
void generateData(int outputLength , double * p);
double evaluate(double xValue);
double evaluate(double * dataSet, int dataLength, int threads);
double normValue();
};
#pragma offload_attribute(pop)
#endif
[/cpp]
myGauss.cpp
[cpp]
#include "myGauss.h"
#include <math.h>
#include <omp.h>
#include <time.h>
#include <stdio.h>
#define PI 3.141592653589793238462
myGauss::myGauss(double paramValueVal){
paramValue = paramValueVal;
oneOverTwoSigSq = 1.0/(2*paramValue*paramValue);
sqrtTwoPi = sqrt(2*PI);
};
myGauss::myGauss(){
paramValue = 1.0;
oneOverTwoSigSq = 1.0/(2*paramValue*paramValue);
sqrtTwoPi = sqrt(2*PI);
};
myGauss::~myGauss(){
};
double myGauss::getParameter(){
return paramValue;
};
void myGauss::setParameter(double newSigma){
paramValue = newSigma;
oneOverTwoSigSq = 1.0/(2*paramValue*paramValue);
};
double myGauss::evaluate(double value){
return exp(-value*value*oneOverTwoSigSq);
};
double myGauss::evaluate(double * dataSet, int dataLength, int threads ){
double NLL = 0;
double norm = 1.0/normValue();
omp_set_num_threads(threads);
#pragma omp parallel for default(none) shared(dataSet,dataLength,norm) reduction(+:NLL)
for(int i=0; i<dataLength; i++){
double evaluated = exp(-dataSet*dataSet*oneOverTwoSigSq);
evaluated*=norm;
NLL+=log(evaluated);
}
return -NLL;
};
double myGauss::normValue(){
return paramValue*sqrtTwoPi;
};
void myGauss::generateData(int length, double * p){
srand(time(NULL));
for(int i=0; i<length; i++){
double rand1 = ((double)rand())/RAND_MAX;
double rand2 = ((double)rand())/RAND_MAX;
//Now doing the box muller method
p = sqrt(-2.0*log(rand1))*cos(2*PI*rand2)*paramValue;
}
};
[/cpp]
MyExp is a class similar to myGauss, but I'm currently not using it in the main method, so if you remove the include "myExp.h" from the main file then the code should compile fine. When I compile I use.
[plain]
icpc -vec-report2 -openmp-report2 -o prog -openmp *.cpp
[/plain]
![](/skins/images/9701FEC4E90D143B667C09F3DB2F340F/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page