char array - my mistake?

Hello!

I’m a bit busy and without see the code deeply, i think that you must review the indexes because in ‘C[i*wC+j]=C[(i-1)*wC+j-1]+1;’ when i = 0, C[j] = C[-wC+j-1] and it is wrong.

When the topology of the problem is in form of matrix, your kernel grid must be two-dimensional too, because is more simple.

If you want, can see the CUDA SDK examples as the vectorAdd example that is easy.

Good luck!

Hello!

I’m a bit busy and without see the code deeply, i think that you must review the indexes because in ‘C[i*wC+j]=C[(i-1)*wC+j-1]+1;’ when i = 0, C[j] = C[-wC+j-1] and it is wrong.

When the topology of the problem is in form of matrix, your kernel grid must be two-dimensional too, because is more simple.

If you want, can see the CUDA SDK examples as the vectorAdd example that is easy.

Good luck!

i correct the case when i==0 (i add else after the first if where (i==0) && (j==0) so this error willn’t appear External Image )

but why after the execution of the kernel there are no modification in C

// execute the kernel

 LCS<<< grid, threads >>>(d_C, d_A, d_B, WA, WB);

 CheckConditionXR_(cudaGetLastError() == cudaSuccess, -1);

// copy result from device to host

	err = cudaMemcpy(h_C, d_C, mem_size_C, cudaMemcpyDeviceToHost);

	CheckConditionXR_(err == cudaSuccess, err)

for (unsigned int i = 0; i < size_C; ++i)

	{

	  printf("C[%d]=%d \t",i, h_C[i]);

	}

and the result is a negativ number in every cell (-842150451)

i correct the case when i==0 (i add else after the first if where (i==0) && (j==0) so this error willn’t appear External Image )

but why after the execution of the kernel there are no modification in C

// execute the kernel

 LCS<<< grid, threads >>>(d_C, d_A, d_B, WA, WB);

 CheckConditionXR_(cudaGetLastError() == cudaSuccess, -1);

// copy result from device to host

	err = cudaMemcpy(h_C, d_C, mem_size_C, cudaMemcpyDeviceToHost);

	CheckConditionXR_(err == cudaSuccess, err)

for (unsigned int i = 0; i < size_C; ++i)

	{

	  printf("C[%d]=%d \t",i, h_C[i]);

	}

and the result is a negativ number in every cell (-842150451)

Still there is an error:

currentIndex goes from 0 to MaxNumberOfThreads (that is gridDim.x*blockDim.x), i.e. in ‘if (A[current_Index-1]==B[current_Index-1])’

the thread 1 access to A[0] and B[0], but the threads > 16 of currentIndex, will access out of bounds of A and B. You have to put a condition.

I don’t know if you know it but currentIndex is as the unique identifier of a thread in the grid. When we have more

threads than the dimension of an array or matrix we have to check if the thread identifier exceeds the dimension of that array or matrix.

I repeat you, check the case of vectorAdd (CUDA SDK), in this example 2 arrays are added and the result goes in a result vector.

In this example, i plays the same role as your currentIndex and the programmer checked that i did not exceed the dimensión of A and B that is N. See it!

Good luck!

Still there is an error:

currentIndex goes from 0 to MaxNumberOfThreads (that is gridDim.x*blockDim.x), i.e. in ‘if (A[current_Index-1]==B[current_Index-1])’

the thread 1 access to A[0] and B[0], but the threads > 16 of currentIndex, will access out of bounds of A and B. You have to put a condition.

I don’t know if you know it but currentIndex is as the unique identifier of a thread in the grid. When we have more

threads than the dimension of an array or matrix we have to check if the thread identifier exceeds the dimension of that array or matrix.

I repeat you, check the case of vectorAdd (CUDA SDK), in this example 2 arrays are added and the result goes in a result vector.

In this example, i plays the same role as your currentIndex and the programmer checked that i did not exceed the dimensión of A and B that is N. See it!

Good luck!

i have checked the example of vectorAdd and the matrixmultiply in the CUDA SDK
but the difference with my algorithm that i didn’t fill in the matrix successively but the cells in the anti-diagonal are fiiled successively

for example
in the first iterative i fill
C[1,1]

_synchthreads();

then

C[1,2],C[2,1]

_synchthreads();

then
C[1,3],C[2,2],C[3,1]

_synchthreads();


until i fill C[N,M] the last anti-diagonal

so the difficulty exist in the stage of changing the index to reach the next Cell.

i have checked the example of vectorAdd and the matrixmultiply in the CUDA SDK
but the difference with my algorithm that i didn’t fill in the matrix successively but the cells in the anti-diagonal are fiiled successively

for example
in the first iterative i fill
C[1,1]

_synchthreads();

then

C[1,2],C[2,1]

_synchthreads();

then
C[1,3],C[2,2],C[3,1]

_synchthreads();


until i fill C[N,M] the last anti-diagonal

so the difficulty exist in the stage of changing the index to reach the next Cell.

i have checked the example of vectorAdd and the matrixmultiply in the CUDA SDK
but the difference with my algorithm that i didn’t fill in the matrix successively but the cells in the anti-diagonal are fiiled successively

for example
in the first iterative i fill
C[1,1]

_synchthreads();

then

C[1,2],C[2,1]

_synchthreads();

then
C[1,3],C[2,2],C[3,1]

_synchthreads();


until i fill C[N,M] the last anti-diagonal

so the difficulty exist in the stage of changing the index to reach the next Cell.

i have checked the example of vectorAdd and the matrixmultiply in the CUDA SDK
but the difference with my algorithm that i didn’t fill in the matrix successively but the cells in the anti-diagonal are fiiled successively

for example
in the first iterative i fill
C[1,1]

_synchthreads();

then

C[1,2],C[2,1]

_synchthreads();

then
C[1,3],C[2,2],C[3,1]

_synchthreads();


until i fill C[N,M] the last anti-diagonal

so the difficulty exist in the stage of changing the index to reach the next Cell.

i start to have some result (!=negativ number) but not which the correct one.

i start to have some result (!=negativ number) but not which the correct one.

why in the stage of comparaison

else

				  C[i*wC+j]=max(C[(i-1)*wC+j],C[i*wC+j-1]);

he read only the cell C[(i-1)*wC+j] (C[i-1][j] ie the cell on the north of which i’m filling)

and he don’t read the cell C[i*wC+j-1] (C[i][j-1] ie the cell on the west of which i’m filling)

is there any problem in the indexation of this cell?

thanks for helping me. :rolleyes:

why in the stage of comparaison

else

				  C[i*wC+j]=max(C[(i-1)*wC+j],C[i*wC+j-1]);

he read only the cell C[(i-1)*wC+j] (C[i-1][j] ie the cell on the north of which i’m filling)

and he don’t read the cell C[i*wC+j-1] (C[i][j-1] ie the cell on the west of which i’m filling)

is there any problem in the indexation of this cell?

thanks for helping me. :rolleyes: