Search code examples
c++modulefortranopenmpstdthread

Use Fortran module in C++ with std::thread


I would like to run a Fortran90 function with different settings in different std::threads, that uses many modules to store the settings and some general data. The problem I see is, that Fortran modules are like singleton objects. When I call the function with two threads they do work on the same module. Is there a way to make modules threadprivate like with openmp?

For example with openmp a module with threadprivate data looks like this:

MODULE EXAMPLE
  USE OMP_LIB
  ! some threadprivate data:
  INTEGER                                          :: VALUE = 0
    ! make value threadprivate.
    !$OMP THREADPRIVATE(VALUE)
  CONTAINS
END MODULE EXAMPLE

Can I do something similar for the std::thread?


Solution

  • C++ standard threads are completely alien to Fortran. there is nothing you can do in Fortran,

    You have to implement everything yourself in a way that stores the data in some other way and not in global (module) variables.