Multitasking in Fortran [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
开发者_如何学运维Closed 8 years ago.
Improve this questionHow can I do multi-tasking and inter-process communication in Fortran?
The main standards to read up on are OpenMP (shared memory multi-threading) and MPI (message passing). Both work well with Fortran (as well as other languages) and you will find a lot of information online.
OpenMP defines a simple way of programming concurrent (parallel) processing in Fortran/C/C++. The process must reside in a same computer (node).
OpenMP 3.0 recent introduces $OMP TASK directive which in principle should allow multitasking the way multithreading is usually done (that is, each thread does its own task). For OpenMP, see this tutorial:
https://computing.llnl.gov/tutorials/openMP/
or specs in http://www.openmp.org/
I won't address interprocess communication (IPC) since I am not familiar with this. I believe you can do POSIX function calls if that what you want. If your compiler supports some Fortran 2003 constructs (e.g. gfortran >= 4.4) then you can use the nice C-Fortran interoperability provided by ISO_C_BINDING standard module. Then with proper care you can call posix functions that can provide IPC functionalities. That's my 2c.
Fortran2008 also has coarrays, which allows distributed-memory computing from within the language itself, and do concurrent
, which allows for functionality similar to an OpenMP parallel do loop. Right now, only the newest intel compiler fully supports these, and g95 has partial support; however, they are actively being worked on by the other compiler vendors, including gfortran.
You do concurrency in Fortran in the same way you would do this in any other language: Spawn a pthread, use OpenMP, use MPI, fork() ... whatever suits your need best.
Systems APIs are often in C (cf. POSIX and Windows API), but interacting with C is a fact of life, regardless of which programming language you use.
The "do concurrent" contruct in Fortran 2008 still does not have a lot of compiler support, even in 2015.
精彩评论