Hello!
I have an existing function, which i want to speed up using cuda. I am neither an expert in cuda nor in c++, but i understand the basics. So here ist the function. I would be glad if s.o. could help me implementing cuda:
void sortcut(int i, int j)
{
int k;
GLdouble swap;
GLdouble ztol = dx/2;
//Schnittwertliste sortieren, so dass absolut groesster Z-Wert an erster Stelle
for(int k=1; k <= cutval[i][j][0]; k++)
{
for(int l=2; l <= cutval[i][j][0]-k+1; l++)
{
if(fabs(cutval[i][j][l]) > fabs(cutval[i][j][l-1]))
{
swap = cutval[i][j][l];
cutval[i][j][l] = cutval[i][j][l-1];
cutval[i][j][l-1] = swap;
}
}
}
//Schnittwerte in Reihenfolge bringen
k=1;
while (k < cutval[i][j][0])
{
if ((cutval[i][j][k]<0) && (cutval[i][j][k+1]>0) && (fabs(cutval[i][j][k]-cutval[i][j][k-1]) < ztol))
{
for(int l=k; l<cutval[i][j][0]-1; l++) cutval[i][j][l]=cutval[i][j][l+2];
cutval[i][j][0]-=2;
}
else if ((cutval[i][j][k]>0) && (cutval[i][j][k+1]<0))
{
cutval[i][j][k+1]=fabs(cutval[i][j][k+1]);
k+=2;
}
else //if (cutval[i][j][k]<=0)
{
for(int l=k; l<cutval[i][j][0]; l++) cutval[i][j][l]=cutval[i][j][l+1];
cutval[i][j][0]--;
}
}
if ((int)cutval[i][j][0]%2==1) cutval[i][j][0]--; //ungerade Anzahl von Schnitten entfernen
}
it sorts different z-values first by the absolute value using bubble-sort and after that it brings the in the order of changing signs (+ - + - + and so on).
Therefore the array cutval consists of a 2 dimensional “adress” cutval[i][j] that represent the position of the values on 2-dimensional grid. The first element of the third dimension is the number of values to sort. so cutval[i][j][0] is 0 or bigger.
Thanks for any help!!!