# \#fortran

**URL:** https://discourse.julialang.org/tag/fortran/39.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Reading Fortran-style Complex Numbers From File](https://discourse.julialang.org/t/reading-fortran-style-complex-numbers-from-file/137453)

<div class="topic-metadata">

**Author:** [@ducksoverip](https://discourse.julialang.org/u/ducksoverip)\
**Replies:** 14\
**Last updated:** [June 7, 2026, 2:56am UTC](https://discourse.julialang.org/t/reading-fortran-style-complex-numbers-from-file/137453 "2026-06-07T02:56:47Z")

</div>

Part of my inherited research code is a highly parallelized Fortran90 program that produces, as its primary output, a large text file (~1 GB) of complex numbers in the following format: (1.014631909321741E-002,-1.82546…

---

## [Disable memory alignment inside struct](https://discourse.julialang.org/t/disable-memory-alignment-inside-struct/132942)

<div class="topic-metadata">

**Author:** [@Yotam\_Ohad](https://discourse.julialang.org/u/Yotam_Ohad)\
**Replies:** 2\
**Last updated:** [October 8, 2025, 3:37pm UTC](https://discourse.julialang.org/t/disable-memory-alignment-inside-struct/132942 "2025-10-08T15:37:24Z")

</div>

I have a (somewhat old) file that was created from a Fortran script and contains a struct without any padding. I try to read the file as follows struct Foo id::UInt32 Value::Int64 end io = open(filepath, "r") ro…

---

## [Functionality like the SAVE statement in Fortran?](https://discourse.julialang.org/t/functionality-like-the-save-statement-in-fortran/127268)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 30\
**Last updated:** [March 25, 2025, 2:37pm UTC](https://discourse.julialang.org/t/functionality-like-the-save-statement-in-fortran/127268 "2025-03-25T14:37:38Z")

</div>

I am converting some Fortran code to Julia, and I noticed the fortran code uses the SAVE statement (SAVE (FORTRAN 77 Language Reference)). I have very little experience in Fortran, but it seems like this statement allow…

---

## [Replicating formatting from Fortran code output](https://discourse.julialang.org/t/replicating-formatting-from-fortran-code-output/127036)

<div class="topic-metadata">

**Author:** [@trung](https://discourse.julialang.org/u/trung)\
**Replies:** 6\
**Last updated:** [March 17, 2025, 3:37pm UTC](https://discourse.julialang.org/t/replicating-formatting-from-fortran-code-output/127036 "2025-03-17T15:37:38Z")

</div>

I am trying to replicate the formatting from a Fortran code output in Julia. Here is a MWE. program formattest implicit none integer:: iyd real(4):: d(4),t iyd = 10000 d = 9.999e-38 t = 1.053e10…

---

## [Allocatable Multidimensional Arrays in Fortran](https://discourse.julialang.org/t/allocatable-multidimensional-arrays-in-fortran/119535)

<div class="topic-metadata">

**Author:** [@Jason\_Meziere](https://discourse.julialang.org/u/Jason_Meziere)\
**Replies:** 9\
**Last updated:** [September 20, 2024, 2:43pm UTC](https://discourse.julialang.org/t/allocatable-multidimensional-arrays-in-fortran/119535 "2024-09-20T14:43:06Z")

</div>

I am attempting to wrap a fortran package in Julia. In many of the functions, there are 2D arrays that are specified as ALLOCATABLE. Does Julia have a way to handle this? And what is the proper way to pass these values i…

---

## [How to manage Fortran file units in Julia?](https://discourse.julialang.org/t/how-to-manage-fortran-file-units-in-julia/116688)

<div class="topic-metadata">

**Author:** [@Abhro](https://discourse.julialang.org/u/Abhro)\
**Replies:** 3\
**Last updated:** [July 6, 2024, 1:06pm UTC](https://discourse.julialang.org/t/how-to-manage-fortran-file-units-in-julia/116688 "2024-07-06T13:06:38Z")

</div>

I’m calling a Fortran subroutine through @ccall which is declared as subroutine data\_input(..., fileunit) integer, intent(out) :: fileunit ... open(newunit = fileunit, ...) ... end subroutine And various other Fortran …

---

## [How to pass variables to several levels up without going through headings (arguments) in functions](https://discourse.julialang.org/t/how-to-pass-variables-to-several-levels-up-without-going-through-headings-arguments-in-functions/112582)

<div class="topic-metadata">

**Author:** [@fmontans](https://discourse.julialang.org/u/fmontans)\
**Replies:** 24\
**Last updated:** [April 6, 2024, 12:28pm UTC](https://discourse.julialang.org/t/how-to-pass-variables-to-several-levels-up-without-going-through-headings-arguments-in-functions/112582 "2024-04-06T12:28:46Z")

</div>

In fortran90, there are two ways to pass variables that is not through the function/subroutine heading/arguments. Those are common blocks (old Fortran77 style) or modules (new fortran90 style). This is extremely useful i…

---

## [Julia code becomes slower on running on supercomputers and does not scale well when parallelizing with Base.Threads](https://discourse.julialang.org/t/julia-code-becomes-slower-on-running-on-supercomputers-and-does-not-scale-well-when-parallelizing-with-base-threads/108439)

<div class="topic-metadata">

**Author:** [@Uranium238](https://discourse.julialang.org/u/Uranium238)\
**Replies:** 73\
**Last updated:** [January 22, 2024, 1:21pm UTC](https://discourse.julialang.org/t/julia-code-becomes-slower-on-running-on-supercomputers-and-does-not-scale-well-when-parallelizing-with-base-threads/108439 "2024-01-22T13:21:22Z")

</div>

This question is a continuation / generalization of my previous question. My end goal is to write a parallelized code where the main time taking part is Matrix multiplication and inversion. As per the advice of @ufechner…

---

## [Equivalent Fortran function is about 4.6 times faster](https://discourse.julialang.org/t/equivalent-fortran-function-is-about-4-6-times-faster/108344)

<div class="topic-metadata">

**Author:** [@jabru](https://discourse.julialang.org/u/jabru)\
**Replies:** 17\
**Last updated:** [January 5, 2024, 8:02am UTC](https://discourse.julialang.org/t/equivalent-fortran-function-is-about-4-6-times-faster/108344 "2024-01-05T08:02:08Z")

</div>

Hey there, for my current project, I wrote a function in plane Julia. It reads #Kappa squared or the square of the inverse debye length Debyelengthinnversesquared(is) = e^2\*beta\*2\*is\*n\_a/(epsilon\*epsilon\_r) #Kappa in …

---

## [Performance and memory in large tensor: Julia vs Fortran](https://discourse.julialang.org/t/performance-and-memory-in-large-tensor-julia-vs-fortran/107218)

<div class="topic-metadata">

**Author:** [@fordonez](https://discourse.julialang.org/u/fordonez)\
**Replies:** 3\
**Last updated:** [December 6, 2023, 3:35pm UTC](https://discourse.julialang.org/t/performance-and-memory-in-large-tensor-julia-vs-fortran/107218 "2023-12-06T15:35:23Z")

</div>

I have a tensor with dimensions (I, J, K, L, M, N), which I am modifying through a loop. I am trying to reach Fortran’s speed in Julia (if (I, J, K, L, M, N) = (100, 100, 100, 100, 10, 10) the Julia/Fortran time ratio is…

---

## [Fortran calling convention when passing an array with unknown size](https://discourse.julialang.org/t/fortran-calling-convention-when-passing-an-array-with-unknown-size/107057)

<div class="topic-metadata">

**Author:** [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Replies:** 2\
**Last updated:** [December 2, 2023, 10:26pm UTC](https://discourse.julialang.org/t/fortran-calling-convention-when-passing-an-array-with-unknown-size/107057 "2023-12-02T22:26:59Z")

</div>

In modern Fortran when an array is passed to a subroutine, we don’t really need to specify its size: the size can be read from size(arr). So the follows function my\_length(arr) real(8), intent(in), dimensio…

---

## [Fortran-Julia interface for program containing non-c-interoperable derived type](https://discourse.julialang.org/t/fortran-julia-interface-for-program-containing-non-c-interoperable-derived-type/106815)

<div class="topic-metadata">

**Author:** [@tmph](https://discourse.julialang.org/u/tmph)\
**Replies:** 6\
**Last updated:** [November 28, 2023, 4:59pm UTC](https://discourse.julialang.org/t/fortran-julia-interface-for-program-containing-non-c-interoperable-derived-type/106815 "2023-11-28T16:59:45Z")

</div>

I’m still new to Julia (and this discourse), but couldn’t find the answer to this question anywhere. I have a large Fortran legacy code base which I’m trying to interface with a high-level language. I got something kind…

---

## [Accessing Fortran derived types from Julia](https://discourse.julialang.org/t/accessing-fortran-derived-types-from-julia/105327)

<div class="topic-metadata">

**Author:** [@danmohedano](https://discourse.julialang.org/u/danmohedano)\
**Replies:** 11\
**Last updated:** [October 24, 2023, 8:54pm UTC](https://discourse.julialang.org/t/accessing-fortran-derived-types-from-julia/105327 "2023-10-24T20:54:39Z")

</div>

Hello everyone. I’ve been performing some tests to try and port some functionality from a Fortran module to Julia. While testing out some of Julia’s interoperability features with Fortran I have run into some issues whe…

---

## [Different output when call Fortran from Julia](https://discourse.julialang.org/t/different-output-when-call-fortran-from-julia/97688)

<div class="topic-metadata">

**Author:** [@X\_Chen](https://discourse.julialang.org/u/X_Chen)\
**Replies:** 5\
**Last updated:** [July 13, 2023, 3:29pm UTC](https://discourse.julialang.org/t/different-output-when-call-fortran-from-julia/97688 "2023-07-13T15:29:40Z")

</div>

Hello! I am trying to use a package in Fortran, and I tested it in Julia - it works perfectly well. Now I am trying to write a function in Julia that I can use it as a normal Julia function. Here is the function code: f…

---

## [Help calling fortran subroutines using ccall](https://discourse.julialang.org/t/help-calling-fortran-subroutines-using-ccall/98572)

<div class="topic-metadata">

**Author:** [@GiovanniLavezzi](https://discourse.julialang.org/u/GiovanniLavezzi)\
**Replies:** 0\
**Last updated:** [May 9, 2023, 8:02pm UTC](https://discourse.julialang.org/t/help-calling-fortran-subroutines-using-ccall/98572 "2023-05-09T20:02:20Z")

</div>

Hi, I’m trying to replicate SWxTREC/pymsis in Julia, specifically the fortran call of the following subroutines (pymsis/src/wrappers at main · SWxTREC/pymsis · GitHub). To do so, I have created the following fortran scri…

---

## [Correct way to ccall a Fortran subroutine requiring pointers](https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191)

<div class="topic-metadata">

**Author:** [@lucifer1004](https://discourse.julialang.org/u/lucifer1004)\
**Replies:** 3\
**Last updated:** [May 2, 2023, 11:27am UTC](https://discourse.julialang.org/t/correct-way-to-ccall-a-fortran-subroutine-requiring-pointers/98191 "2023-05-02T11:27:01Z")

</div>

Given the following Fortran code: MODULE PTR IMPLICIT NONE REAL, SAVE, TARGET, ALLOCATABLE :: A(:, :), B(:, :) CONTAINS SUBROUTINE INIT(AP, BP) REAL, POINTER :: AP(:, :), BP(:, :) ALLOCATE(A(6, 6…

---

## [Compiler optimizations for ComplexF64 vs Fortran](https://discourse.julialang.org/t/compiler-optimizations-for-complexf64-vs-fortran/96346)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 7\
**Last updated:** [March 30, 2023, 6:23pm UTC](https://discourse.julialang.org/t/compiler-optimizations-for-complexf64-vs-fortran/96346 "2023-03-30T18:23:49Z")

</div>

My former colleague Michael Rutter now posted his comparison of Fortran compilers regarding their optimization of complex number arithmetic. I was wondering if anyone would like to see how Julia matches these? For examp…

---

## [Embedding Julia code in Fortran](https://discourse.julialang.org/t/embedding-julia-code-in-fortran/96010)

<div class="topic-metadata">

**Author:** [@gradureau](https://discourse.julialang.org/u/gradureau)\
**Replies:** 10\
**Last updated:** [March 16, 2023, 8:41am UTC](https://discourse.julialang.org/t/embedding-julia-code-in-fortran/96010 "2023-03-16T08:41:11Z")

</div>

Hey everyone, I am fairly new to Julia and am interested to do machine learning with it. So far I learnt how to code in Julia and how to use the Flux library. Yet, My goal is to use trained neural networks in a fortran …

---

## [When I call a function from fortran complied dll in windows, there is a "EXCEPTION\_ACCESS\_VIOLATION" error](https://discourse.julialang.org/t/when-i-call-a-function-from-fortran-complied-dll-in-windows-there-is-a-exception-access-violation-error/93554)

<div class="topic-metadata">

**Author:** [@liaoweiyang2017](https://discourse.julialang.org/u/liaoweiyang2017)\
**Replies:** 0\
**Last updated:** [January 26, 2023, 5:23am UTC](https://discourse.julialang.org/t/when-i-call-a-function-from-fortran-complied-dll-in-windows-there-is-a-exception-access-violation-error/93554 "2023-01-26T05:23:54Z")

</div>

The julia version: (base) D:\\julia\_code\_w\\WEM3D\\WEM3D\\test\\Fwd0114\>julia \_ \_ \_ \_(\_)\_ | Documentation: https://docs.julialang.org (\_) | (\_) (\_) | \_ \_ \_| |\_ \_\_ \_ | Type "?" f…

---

## [\[ANN\] Julia back-end for LFortran](https://discourse.julialang.org/t/ann-julia-back-end-for-lfortran/87859)

<div class="topic-metadata">

**Author:** [@lucifer1004](https://discourse.julialang.org/u/lucifer1004)\
**Replies:** 4\
**Last updated:** [September 27, 2022, 7:53pm UTC](https://discourse.julialang.org/t/ann-julia-back-end-for-lfortran/87859 "2022-09-27T19:53:51Z")

</div>

This is not a Julia package, but is very related. I just implemented a Julia back-end for the LFortran project. Since it is still very primitive, it would be great if more users could try it and submit issues or provide…

---

## [Help with updating fortran wrapper](https://discourse.julialang.org/t/help-with-updating-fortran-wrapper/86221)

<div class="topic-metadata">

**Author:** [@JackDunnNZ](https://discourse.julialang.org/u/JackDunnNZ)\
**Replies:** 2\
**Last updated:** [August 23, 2022, 10:16pm UTC](https://discourse.julialang.org/t/help-with-updating-fortran-wrapper/86221 "2022-08-23T22:16:14Z")

</div>

I maintain the GLMNet.jl package, which wraps the fortran internals of the glmnet R package. This fortran dependency is shipped as glmnet\_jll, and currently uses the version built here This version of the fortran code d…

---

## [Shared library code crashing, but only from REPL](https://discourse.julialang.org/t/shared-library-code-crashing-but-only-from-repl/81314)

<div class="topic-metadata">

**Author:** [@andrew\_s](https://discourse.julialang.org/u/andrew_s)\
**Replies:** 0\
**Last updated:** [May 19, 2022, 4:03pm UTC](https://discourse.julialang.org/t/shared-library-code-crashing-but-only-from-repl/81314 "2022-05-19T16:03:19Z")

</div>

I am calling a Fortran shared library in my program. If I run my Julia program (which calls the Fortran library) everything runs as expected. However, if I run exactly the same code in the Julia REPL (connected to Visu…

---

## [Communicating a struct to Fortran with a large array](https://discourse.julialang.org/t/communicating-a-struct-to-fortran-with-a-large-array/80453)

<div class="topic-metadata">

**Author:** [@james3](https://discourse.julialang.org/u/james3)\
**Replies:** 0\
**Last updated:** [May 3, 2022, 10:28pm UTC](https://discourse.julialang.org/t/communicating-a-struct-to-fortran-with-a-large-array/80453 "2022-05-03T22:28:08Z")

</div>

What is the best practice for communicating a struct to Fortran that contains a large array object? (In practice, the struct s\_t that I define below will also contain other elements). I was doing something like using S…

---

## [Return matrix of Cchar from Fortran library](https://discourse.julialang.org/t/return-matrix-of-cchar-from-fortran-library/80430)

<div class="topic-metadata">

**Author:** [@james3](https://discourse.julialang.org/u/james3)\
**Replies:** 2\
**Last updated:** [May 3, 2022, 3:28pm UTC](https://discourse.julialang.org/t/return-matrix-of-cchar-from-fortran-library/80430 "2022-05-03T15:28:31Z")

</div>

I have been having difficulty getting a Fortran subroutine return a matrix of Cchar to Julia (contained in a struct; in practice there are other components in s\_t below). On the Fortran side I have module test use …

---

## [Calling Fortran subroutine from Julia passing array arguments](https://discourse.julialang.org/t/calling-fortran-subroutine-from-julia-passing-array-arguments/79340)

<div class="topic-metadata">

**Author:** [@Marie](https://discourse.julialang.org/u/Marie)\
**Replies:** 5\
**Last updated:** [April 11, 2022, 2:13pm UTC](https://discourse.julialang.org/t/calling-fortran-subroutine-from-julia-passing-array-arguments/79340 "2022-04-11T14:13:25Z")

</div>

Fortran subroutine looks like this: subroutine MatMult(a, b, m, n, k, answer) !DEC$ ATTRIBUTES DLLEXPORT :: MatMult !DEC$ ATTRIBUTES ALIAS: 'MatMult' :: MatMult !DEC$ ATTRIBUTES REFERENCE :: a …

---

## [Fortran to Julia with a nested struct](https://discourse.julialang.org/t/fortran-to-julia-with-a-nested-struct/79099)

<div class="topic-metadata">

**Author:** [@james3](https://discourse.julialang.org/u/james3)\
**Replies:** 1\
**Last updated:** [April 6, 2022, 2:01pm UTC](https://discourse.julialang.org/t/fortran-to-julia-with-a-nested-struct/79099 "2022-04-06T14:01:51Z")

</div>

This is following on from a question I had here https://discourse.julialang.org/t/fortran-to-julia-struct/79081. I’m still trying to get Julia speaking to a Fortran library. My problem now is dealing with nested structs…

---

## [Fortran to Julia struct](https://discourse.julialang.org/t/fortran-to-julia-struct/79081)

<div class="topic-metadata">

**Author:** [@james3](https://discourse.julialang.org/u/james3)\
**Replies:** 1\
**Last updated:** [April 6, 2022, 3:10am UTC](https://discourse.julialang.org/t/fortran-to-julia-struct/79081 "2022-04-06T03:10:12Z")

</div>

I’m having some difficulty calling some Fortran code from Julia. I have some Fortran code like the following module fortranjulia use, intrinsic :: iso\_c\_binding implicit none type, bind(c) :: m\_t integer(c…

---

## [Julia 3 times slower than Fortran reading integer data from ASCII file](https://discourse.julialang.org/t/julia-3-times-slower-than-fortran-reading-integer-data-from-ascii-file/78516)

<div class="topic-metadata">

**Author:** [@jman87](https://discourse.julialang.org/u/jman87)\
**Replies:** 14\
**Last updated:** [March 26, 2022, 7:20pm UTC](https://discourse.julialang.org/t/julia-3-times-slower-than-fortran-reading-integer-data-from-ascii-file/78516 "2022-03-26T19:20:13Z")

</div>

Hey all, I’ve been dabbling with Julia since the 0. days. Up to point I haven’t had any real performance issues, but am now needing to read in some fairly large size files (think finite element / mesh data with millions …

---

## [Can I pass MPI.jl communicator to the Fortran side?](https://discourse.julialang.org/t/can-i-pass-mpi-jl-communicator-to-the-fortran-side/76547)

<div class="topic-metadata">

**Author:** [@lucifer1004](https://discourse.julialang.org/u/lucifer1004)\
**Replies:** 4\
**Last updated:** [February 16, 2022, 1:36pm UTC](https://discourse.julialang.org/t/can-i-pass-mpi-jl-communicator-to-the-fortran-side/76547 "2022-02-16T13:36:43Z")

</div>

I have a Fortran program that uses File I/O, which I want to modify to a subroutine so that I can directly call it from Julia without writing to / reading from files. The problem is that the program depends heavily on M…

---

## [Calling Fortran functions that use MPI](https://discourse.julialang.org/t/calling-fortran-functions-that-use-mpi/76394)

<div class="topic-metadata">

**Author:** [@lucifer1004](https://discourse.julialang.org/u/lucifer1004)\
**Replies:** 0\
**Last updated:** [February 14, 2022, 7:36am UTC](https://discourse.julialang.org/t/calling-fortran-functions-that-use-mpi/76394 "2022-02-14T07:36:47Z")

</div>

I have used ccall() a few times, but I wonder what I should do when the callee Fortran function uses MPI itself? Can MPI.jl work in this case?

[Next page](https://discourse.julialang.org/tag/fortran/39.md?match_all_tags=true&page=1&tags%5B%5D=fortran)
