a loop in ray generation program can't be excuted completely

I met a problem when applying Optix to parellel computation, in fact, my agorithim is quite simple. In the ray generation program, a loop wass created,
it was as following.

for(int i=0;i<288;i++)
{
	// do some computation
	calcuate_solar_irradiance();
	.....
	if(launch_index ==2000)
		printf("i=%d\n",i);
}

In the loop, I would call some other device functions which is a little complicated.
The problem is that the loop can’t be excuted completely. As you can see, A printf is used to display how many times the loop is excuted.
In my case, the program terminates when i=73 without error. But if I comment the function which is complicated, the program terminates normally,and i can reach 288.
I am curious why the problem appear, is it because the called function is time consuming? What should I do to solve the problem?
Thank you for your answers.

A couple of things:

Are exceptions enabled?

Are you sure it’s not timing out? Recall that there are watch dog timers that will kill threads if they run too long. This can be disabled in different ways depending on OS. It sounds like this may be your problem. I just use a simple try/catch to report such errors:

try { context->launch( ... ); }
catch(optix::Exception e) { std::cerr << "Error: " << e.what() << std::endl; }

Thank you for your answer.
Fisrst, I have enabled the exceptions, it is done like that:

context->setExceptionEnabled(RT_EXCEPTION_ALL,1);

Second, I also use the try/catch structure to catch the possible exception. But the program terminates without any exception or error, it seems like the program terminate normally untill I check how many times the loop are excuted. It is quite weird.
Third, I have changed the Timeout Detection configuration by changing the regedit value, it helpless. In fact, my program won’t take too much time, the program terminates less than 1s. In order to make sure whether it is the problem of timeout, the loop is excuted 100000 times, which will take 12s, the premise is that the function is commented.Then the program terminates normally.

for(int i=0;i<100000;i++)
{
	// do some computation
	//calcuate_solar_irradiance();
	.....
	if(launch_index ==2000)
		printf("i=%d\n",i);
}

So I am sure it has noting to do with timeout, and it also gives nothing exception or error. This is why it make me confused.

You should not be using printf inside an OptiX kernel. Instead, try using rtPrintf.
It might seem weird that your problem is linked to this, but that would not be the first time a weird problem is linked to printf usage inside OptiX.

I agree with HamzaC, but I’ve also had problems using rtPrintf inside a loop. I think you need a different way to check how many times your loop executes:

int i=0;
for(;i<288;i++)
{
	// do some computation
	calcuate_solar_irradiance();
	.....
}
if(launch_index ==2000)
	rtPrintf("i=%d\n",i);

This will tell you if the problem is with the number of times the loop executes or if it is a problem with your print statement.

Thank you, @over0219,@HamzaC and @nljones.
Thank you for your kind-hearted help, I have learnt a lot from you. But all these have nothing to do with my problem, fortunatelly, I have found what caused the problem. unfortunately, I have not decided how to solve it. I will create another topic to discuss it.