how to get which core is running a function in par

If you have a simple question and just want an answer.
mogren3000
Member++
Posts: 19
Joined: Tue Apr 29, 2014 8:12 am

how to get which core is running a function in par

Post by mogren3000 »

Hi. I have this function to calculate prime. What i wonder is if its possible to get which core is running the prime function in par.

Lets say that I use all eight cores and i want to calculate prime number and print the index of the core each number that gets calculated.

This is what the print should look like. 0001110022445503006886652

So this above should represent on which core the calculation is made.
When using par as follows:

par {
on tile[0].core[0]: prime(2,1000,0,c);
on tile[0].core[1]: prime(2,1000,0,c);
}

Is this possible, have tried with chanends but i am a bit lost. Here I all my code so far.

#define NUM_PER_CORE 1000
#define NUM_CORES 8
[[combinable]]
void prime(int start, int stop, int index, chanend c)
{
int i, j, idx=0,results[NUM_PER_CORE];
while(1)
{
select
{
case c :> index:
{
for(i=start;i<=stop;i++)
{
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
printf("%d",results[idx++] = index);
}
}
}
}
break;
}
}
}
int main()
{
chan c;
par
{
on tile[0].core[0]: prime(2,1000,0,c);
on tile[0].core[1]: prime(1001,2000,1,c);
}
return 0;
}

User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

In xs1.h there is an API available for this purpose

unsigned get_logical_core_id(void)

Returns the identifier of the logical core on which the caller is running. The identifier uniquely identifies a logical core on the current tile.