Tickers in Co-array Fortran
In Co-array Fortran, we can simulate tickers using a combination of the sleep
subroutine from the iso_fortran_env
module and a loop. While Co-array Fortran doesn’t have built-in tickers or channels like some other languages, we can create a similar effect.
In this program:
We use the
sleep
subroutine to pause execution for 500 milliseconds (0.5 seconds) between each tick.We use a
do while
loop to simulate the continuous ticking until a condition is met.The
cpu_time
subroutine is used to get the current time and calculate the elapsed time.We print a message for each tick, showing the time elapsed since the start of the program.
After approximately 1.6 seconds (slightly more due to execution time), we stop the ticker by setting
done
to.true.
.
When we run this program, it should tick 3 times before stopping, similar to the original example:
Note that the exact timing may vary slightly due to system-specific factors and the precision of the sleep
subroutine.
This example demonstrates how to create a simple ticker-like behavior in Co-array Fortran. While it doesn’t use the parallel features of Co-array Fortran, it provides a similar functionality to the original example.