# Problem with sum of two structs without ripetition

Hi people, the following code does the sum of two structs without ripetition and, for each couple, it does an “if” that, if success, stores the result in a vector:

``````__device__ void createPI0(QVECT *Gamma, PI_0 *Pi0, unsigned long int N, unsigned long int N2, float M0, float del, int *dimPi0){

//Dichiarazioni variabili locali sul device

int linIdx, i, z, j, loc, sh, tid;

float massa;

QVECT Candidato;

//Dichiarazione variabile condivisa sul device

__shared__ int Ind;

//Il primo thread del blocco inizializza la variabile shared

Ind = *dimPi0;

}

tid = blockDim.x*blockDim.y*(blockIdx.x + gridDim.x* blockIdx.y) + sh;

//Algoritmo per il calcolo degli indici giusti in base al thread

if (tid<N2){

linIdx=N2-tid;

i=int(N - 0.5 - sqrt(0.25 - 2 * (1 - linIdx)));

z=(N+N-1-i)*i;

j=tid - z/2 + 1 + i;

if (i==j){

i=i-1;

j=N-1;

}

Candidato.x=Gamma[i].x+Gamma[j].x;

Candidato.y=Gamma[i].y+Gamma[j].y;

Candidato.z=Gamma[i].z+Gamma[j].z;

Candidato.Ene=Gamma[i].Ene+Gamma[j].Ene;

//Controllo massa

massa=(Candidato.Ene*Candidato.Ene)-(Candidato.x*Candidato.x)-(Candidato.y*Candidato.y)-(Candidato.z*Candidato.z);

if(massa>M0-del && massa<M0+del){

Pi0[loc].x=Candidato.x;

Pi0[loc].y=Candidato.y;

Pi0[loc].z=Candidato.z;

Pi0[loc].Ene=Candidato.Ene;

Pi0[loc].g1=i;

Pi0[loc].g2=j;

}

}