I have a CUDA function like this…
========= function =============
device void func_1(int a)
{
a =a+1 ;
if( a >5 )
break ; <--------------------- I want to stop and go back the main function
}
global void main(int ok)
{
func_1<<<1,1>>>(ok) ;
}
=============================
Does anyone know the cuda instruction which is like the C “break”?
Thanks~ External Image
You don’t want the “break” statement. You want the “return” statement. Outside of a loop or switch statement “break” does nothing.
haha~sorry~I correct the func_1()
I want to avoid doing the process1~3 and finish the program .
How to do it? Thanks~~ External Image
========= function =============
device void func_1(int a)
{
a =a+1 ;
if( a >5 )
break ; <--------------------- I want to stop and go back the main function
process_1 ;
process_2 ;
process_3 ;
.
.
}
global void main(int ok)
{
func_1<<<1,1>>>(ok) ;
}
=============================
return instead of a break like was said before.
Hello~I have another question about “break”
=============== C code =================
for (int i = 0 ; i<5 ; i++) //<—LOOP 1
{
for (int j = 0; j<9 ; j++) //<—LOOP 2
{
if( a[i][j] < 30 )
{
a [i][j] = a[i][j]*10 ;
break ;
}
}
}
===================================
I want to use the “break” to stop running LOOP2
does anyone know the CUDA instruction like the “break”?
Thanks~
? why can’t you use break ? break is c, it’s the same!
Of course you can use the break statement. It works just as in C and breaks out of the innermost loop. Check the original post: they had no loops and wanted to “break” from the function which is not done by the break statement, but return.