GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - vmagnin/coarray_examples: Modern Fortran examples using parallel features like coarrays, collective subroutines, etc.

BranchesTags
Open more actions menu

Latest commit

 

History

9 Commits
9 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
ppm_coarray_buddhabrot.f90
ppm_coarray_buddhabrot.f90
 
 

Repository files navigation

A Buddhabrot computed with co_sum() and saved in a PPM file

For the moment, this repository contains only one example (but you may also be interested by exploring_coarrays).

ppm_coarray_buddhabrot.f90 is a CLI program drawing a Buddhabrot in a portable pixmap binary format (PPM) file, a very basic uncompressed image file format. Each Fortran image is computing its own Buddhabrot, and they are finally summed using the co_sum() collective subroutine. The process is therefore very similar to what is done in astrophotography.

The Buddhabrot

In the Buddhabrot, the intensity of a pixel is proportional to the number of times it was visited by the $z_n$ complex sequence defining the Mandelbrot set, considering only sequences starting from points not in the Mandelbrot set (and therefore diverging $z_n$ sequences).

Instead of partitioning the complex plane in several images, we have chose to simply use a Monte Carlo algorithm: each image is computing a lot of $z_n$ sequences using $c$ random complex values. At the end, all the results are summed using the co_sum() collective subroutine.

You can modify the contrast by setting the multiplication factor parameter used in the grey level computation.

You can also study the Anti-Buddhabrot by reversing the modulus test:

    if (real(z(iterations))**2 + aimag(z(iterations))**2 < 4._wp) then

to consider only $z_n$ sequences starting from points inside the Mandelbrot set.

Compiling and executing

GFortran>=16.0

Starting from version 16, GFortran supports natively coarrays using shared memory mulithreading on single node machines:

$ gfortran -Ofast -fcoarray=lib ppm_coarray_buddhabrot.f90 -lcaf_shmem && ./a.out

The -lcaf_shmem is necessary until a -fcoarray=shared option is added in a later GFortran release.

You can force the number of images (8 for example) with:

$ export GFORTRAN_NUM_IMAGES=8

You can also add the -march=native -mtune=native options for further optimization.

GFortran<16

You needed to install OpenCoarrays and type that command (8 images here):

$ caf -Ofast ppm_coarray_buddhabrot.f90 && cafrun -n 8 ./a.out

Intel ifx

$ ifx -Ofast -coarray ppm_coarray_buddhabrot.f90 && ./a.out

The number of images can be set with the option -coarray-num-images=8.

Flang

Flang 22.1 offers an experimental support for coarrays with the option -fcoarray.

TODO

  • The loop computing z(k) could be stopped by exit when we escape the computing window containing the whole Mandelbrot set. But the value of the counter should be memorized.
  • We could use the symmetry of the Buddhabrot to improve computing.
  • We could add colours instead of grey levels.

License

Distributed under the MIT license.

References

  • Curcic, Milan. Modern Fortran - Building efficient parallel applications, Manning Publications, 1st edition, novembre 2020, ISBN 978-1-61729-528-7.
  • Metcalf, Michael, John Ker Reid, Malcolm Cohen and Reinhold Bader. Modern Fortran Explained: Incorporating Fortran 2023 (6th edn). Numerical Mathematics and Scientific Computation. Oxford (England): Oxford University Press, 2023, ISBN 978-0-19-887657-1.
  • Thomas Koenig, coarray-tutorial.
  • Ondrej CERTIK's code (MIT license) for PPM format: https://github.com/certik/fortran-utils/blob/master/src/ppm.f90

About

Modern Fortran examples using parallel features like coarrays, collective subroutines, etc.

Topics

coarraycoarray-fortrancoarray-tutorialcoarraysfortranmodern-fortran

Resources

Readme
MIT license
Activity

Stars

4 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.