[quote name=‘avidday’ post=‘998981’ date=‘Feb 11 2010, 03:31 AM’]
Sorry, I can’t answer that based on the 8 lines of code you have shown. The basic problem is that
[codebox]__constant__ int NP_CUDA = 100;
constant int maxnfc_CUDA = 100000;
constant int maxrun_CUDA = 100;
constant int D_CUDA = 10;
constant int F_CUDA = 0.5;
constant int CR_CUDA = 0.9;
device double pswap_cu;
device double trial_cost; // f. of the trial vector
device double mincost = 0;
device double cost[MAXPOP]; // objective function values (f.)
device double best[MAXDIM], bestit[MAXDIM];
device double *x_d;
device double *curpop_cu[MAXPOP];
device double *nxtpop_cu[MAXPOP];
device long lseed_cu = -1234;
device int imin = 0; // index to member with the best cost (obj. func. val.)
device int gen = 0; //Generation[/codebox]
[codebox]global void deCUDA(double* mincost_CU)
{
double temp[100];
int target, d, i, m=0,n;
reset_de();
nfc = 0;
logc = 0;
for ( gen = 1 ; nfc <= maxnfc_CUDA ; gen++ ) {
imin = 0;
for ( target = 0 ; target < NP_CUDA; target++ ) {
differential_mutation(target); // For display value to console
for ( d = 0; d < D_CUDA; d++) {
if ( x_d[d] < low[d] )
x_d[d] = randreal_CUDA ( low[d], 0.005*(hi[d]-low[d]) );
else if ( x_d[d] > hi[d] ) {
double space = 0.005 * ( hi[d] - low[d] );
x_d[d] = randreal_CUDA( hi[d] - space, space );
}
}
trial_cost = DEevaluate(x_d);
if (trial_cost <= cost[target]) {
cost[target] = trial_cost;
dcopy_CUDA(D_CUDA, nxtpop_cu[target], x);
if ( trial_cost < mincost ) { // Was this a new minimum?
mincost = trial_cost; // If so, set mincost to new low.
imin = target;
dcopy_CUDA(D_CUDA, best, x_d);
}
} else {
dcopy_CUDA(D_CUDA, nxtpop_cu[target], curpop_cu[target]);
}
}
dcopy_CUDA(D_CUDA, bestit, best); // Save best member of the current gen.
for ( i = 0 ; i < NP_CUDA ; i++ ) {
pswap_cu = curpop_cu[i];
curpop_cu[i] = nxtpop_cu[i];
nxtpop_cu[i] = pswap_cu; // swap pop. for next gen.
}
if(nfc == maxnfc_CUDA){
temp[m] = mincost;
m++;
}
}
nrun++;
putchar('\n');
for(int f=0 ; f<maxrun_CUDA ; f++){
mincost_CU[f] = temp[f];
}
}[/codebox]
[codebox]device void differential_mutation(int target)
{
int n, L;
int r1, r2, r3;
do r1 = (int)(unirandom_cu()*NP_CUDA); while (r1==target);
do r2 = (int)(unirandom_cu()*NP_CUDA); while (r2==target || r2==r1);
do r3 = (int)(unirandom_cu()*NP_CUDA); while (r3==target || r3==r1 || r3==r2);
dcopy_CUDA(D_CUDA, x_d, curpop_cu[target]);
n = (int)( unirandom_cu() * D_CUDA );
for ( L = 0 ; L < D_CUDA ; L++ ) {
if ( unirandom_cu() < CR_CUDA || L == D_CUDA-1 ) /* change at least 1 parameter */
x_d[n] = curpop_cu[r1][n] + F_CUDA*( curpop_cu[r2][n] - curpop_cu[r3][n] );
n = ( n + 1 ) % D_CUDA;
}
}[/codebox]
[codebox]device void reset_de(){
int n, d;
// Initialize population
for ( n = 0; n < NP_CUDA; n++ ) {
for ( d = 0; d < D_CUDA; d++ )
curpop_cu[n][d] = randreal_CUDA(low[d], hi[d]);
cost[n] = DEevaluate(curpop_cu[n]); // Calculate cost value
}
// Find the best individual at startup
imin = 0;
mincost = cost[0];
for ( n = 1; n < NP_CUDA; n++ ) // collect mincost
if ( cost[n] < mincost ) {
mincost = cost[n];
imin = n;
}
dcopy_CUDA(D_CUDA, best, curpop_cu[imin]); // save best member ever
dcopy_CUDA(D_CUDA, bestit, curpop_cu[imin]); // save best member of generation
}[/codebox]
I choose some part to show, ans this get an error
a value of type “double” cannot be assigned to an entity of type "double *
in red lines.
Help me please… Thank you.