I wanted to use thread id to access an array which is defined as a global variable. But I face the problem in summing by one. Take a look below:
// initial array myU[0..3]={0,0,0,0}, myindex[0..3]={0,1,1,3}
1- tid=0,1,2,3 //tid is threads index
2- id=myindex[tid]; //id=0,1,1,3
3- myU[id]=myU[id]+1;
4- if (myU[id]>1)
//print("id"); // it should print '1'
I supposed after running line 3 I have myU[0]=1,myU[1]=2,myU[3]=1. But myU array has some strange value, like as: myU[0]=0, myU[1]=1, myU[3]=3. I don't know why.
My final goal is to have the id(in line 4), which they summed by one, more than one time).