https://github.com/wcota/tictoc-fortran
TicToc routine - Fortran
https://github.com/wcota/tictoc-fortran
fortran fortran-package-manager fpm timer
Last synced: 3 months ago
JSON representation
TicToc routine - Fortran
- Host: GitHub
- URL: https://github.com/wcota/tictoc-fortran
- Owner: wcota
- Created: 2018-10-14T19:11:13.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-26T05:02:14.000Z (over 1 year ago)
- Last Synced: 2024-11-26T05:28:10.763Z (over 1 year ago)
- Topics: fortran, fortran-package-manager, fpm, timer
- Language: Fortran
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tictoc-fortran
TicToc routine - Fortran
## Usage
Copy the file `src/tictoc_mod.f90` or add the package as a dependence using the [Fortran Package Manager](https://fpm.fortran-lang.org/) (Fpm):
```toml
[dependencies]
tictoc-fortran.git = "https://github.com/wcota/tictoc-fortran"
```
Import the module using `use tictoc_mod`. This package provides the `tictoc_t` object. Create one using
```fortran
type(tictoc_t) :: ctimer
```
Reset the timer:
```fortran
call ctimer%reset()
```
Use the `tic` to start the clock, and `toc` to pause it:
```fortran
call ctimer%tic()
! do something
call ctimer%toc()
! do anything else
call ctimer%tic()
! do something
call ctimer%toc()
```
To see how much time was spent doing something, use the `real` variable `t_tot`:
```fortran
write(*,*) ctimer%t_tot
```
A possible usage would be to stop the simulation after `x` samples if the program is taking too long:
```fortran
call ctimer%reset()
call ctimer%tic()
sampling: do sample=1,1000
if (ctimer%now() > 5.0_dp * 60.0_dp) exit sampling
! dynamics
enddo sampling
```
## Example
An example is available at `example/example.f90`. To run it with Fpm, use `fpm run --example`. Expected output:
```txt
Project is up to date
CPU TIME =
0.35635800000000001
Now measuring inside the loop...
CPU TIME =
0.57127699999999348
```
Tested with `gfortran`, `ifort` and `ifx` compilers.