我正在研究CUDA中的并行Smith Waterman算法实现,但现在遇到了一些麻烦。得分矩阵的最后两行根本没有计算,它们只显示零。矩阵的其余部分是正确计算的。
算法分两个阶段进行。首先,线程数增加到seq长度的大小,然后收缩回0.使用不同数量的线程和k值重复调用内核。 c是我的得分矩阵,a,b是序列,k是第k个反对角线(i + j = k)。如史密斯沃特曼算法中的值偏移1。
以下是我的内核:
__global__ void SmithWKernelExpand(int (*c)[arraySize+1], const char *a, const char *b, int *k)
{
int i = threadIdx.x+1;
int j = ((*k)-i)+1;
int north=c[i][(j)-1]-1; //Indel
int west=c[i-1][j]-1;
int northwest;
if (((int) a[i-1])==((int)b[(j)-1]))
northwest=c[i-1][(j)-1]+2; //Match
else
northwest=c[i-1][(j)-1]-1; //Mismatch
//c[i][j] = max(max(north, west),max(northwest,0));
c[i][j]=(*k); //Print the number of anti diagonal - For Debugging
}
__global__ void SmithWKernelShrink(int (*c)[arraySize+1], const char *a, const char *b, int *k)
{
int i = threadIdx.x+((*k)-arraySize)+1;
int j = ((*k)-i)+1;
int north=c[i][(j)-1]-1; //Indel
int west=c[i-1][j]-1;
int northwest;
if (((int) a[i-1])==((int)b[(j)-1]))
northwest=c[i-1][(j)-1]+2; //Match
else
northwest=c[i-1][(j)-1]-1; //Mismatch
//c[i][j] = max(max(north, west),max(northwest,0));
c[i][j]=(*k); //Print the number of anti diagonal - For Debugging
}
输出结果为:
0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8
0 2 3 4 5 6 7 8 9
0 3 4 5 6 7 8 9 10
0 4 5 6 7 8 9 10 11
0 5 6 7 8 9 10 11 12
0 6 7 8 9 10 11 12 13
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
有人可以帮我解决这个问题吗?