Collect profiler information only for a do-loop

Could you tell me how to collect profiler information only for a DO-LOOP in a source code written in Fortran and OpenACC ?

Here is the source code. When I would like to collect profiler information using “Nsight system” between “cudaProfilerStart” and “cudaProfilerStop”, is the following correct ? or not ?


do while

error =0.d0

call cudaProfilerStart
!$acc kernels
do j = 2, m-1
do i = 2, n-1
Anew(i,j) = 0.25 * ( A(i,j+1) + A(i,j-1) &
+ A(i-1,j) + A(i+1,j) )
error = max(error, abs(Anew(i,j) - A(i,j)))
end do
end do
!$acc end kernels
call cudaProfilerStop

!$acc kernels
do j = 2, m-1
do i = 2, n-1
A(i,j) = Anew(i,j)
end do
end do
!$acc end kernels

   if ( mod (iter,100) == 0 ) print *, iter, error
  iter = iter + 1

end do


And at the time, I think I am going to run the following command, in order to collect profiler information using “Nsight system” between “cudaProfilerStart” and “cudaProfilerStop”, is the following correct ? or not ?

% nsys profiler --capture-range=cudaProfilerApi --trace=cuda,openacc …

That should be correct, although if the do loop doesn’t take enough time, the profiler may fail to be able to get all of the information you are hoping for.

Thank you for the reply to me and checking if the source code is correct.
Okay, I will try as you said.