/r/fortran
The choice for high performance (scientific) computing!
Suggested Links:
Other sub-reddits:
If your submission does not appear, please message the moderators!
IRC: freenode, #fortran
/r/fortran
Many people come here with a wide variety of questions, a lot of them are answered perfectly with resources present in the fortran-lang.org website. The tutorials there are great as a beginner and also as an experienced dev.
I'd like to petition to have links to the website and maybe the discourse in a visible place in the subreddit. My hope would be that people will come back and say: the website does not cover this and this and that, we can hivemind a solution and update the website to teach about the problem.
I'm not trying to make people feel bad about asking simple questions, we all start somewhere! But we have very nice resources available that should get attention :)
From todays NYT about Annie Easely ,an Black "computer" at NASA: "Her responsibilities changed and grew over the decades. She became a computer programmer, working in languages like Simple Object Access Protocol, which is used to transmit data and instructions over networks, and Formula Translating System, or Fortran. She analyzed systems that handled energy conversion and aided in the design of alternative power technology, including the batteries used in early hybrid vehicles."
Hello! I’m having trouble setting up fortran with vscode on my Mac m1 system- Stack exchange said to use lldb (I have it installed already through xcode) since gdb doesn’t work, but I’m really not sure what to do with the launch.json file as I’m a complete beginner to fortran and know nothing about C/C++ either. Could anyone please tell me what I’m supposed to put in the program and cwd fields?
Additionally, despite me having installed fortls in the environment I’m working in already, vscode keeps prompting me to install it and then when I click install it says there's been a problem and I should install it manually. Not sure what’s happening here, any help would be appreciated!
https://code.visualstudio.com/docs/cpp/lldb-mi This is the guide I tried to follow to get the debugger working on my system.
Thanks!
Does anyone know how I can integrate this https://github.com/minitu/baseenv/tree/master/nodecart into a fortran code? Quite confusing realky.
Hey all, having an issue getting OpenMP to work on an old fixed form fortran code.
Essentially there are 3 sets of nested loops within a do loop over variable ii.
I've tried to parallelize each of them.
I run into errors that say "Number of threads: 1.9480931810122940E+227"
(You can check the debugging print statements I've used in the 3rd loop)
And when I try to change the # of threads with export OMP_NUM_THREADS=
There is no improvement in speed
The code compiles with nvfortran -mp file.f -o output
And it can run fine, but I can't control # of threads and am not sure I implemented OpenMP properly for fixed form fortran.
I have a simple code running matrix addition with OpenMP that I do have working.
Appreciate any help pointing me in right direction!
Hi all, I’m having some trouble implementing OpenMP on a fortran code w/ nvidia compiler nvfortran. The code is older and originally written in fixed form fortran.
I added parallel for loops, and the program compiles & runs but increasing thread count doesn’t change the run time.
Oddly, I remember having it working (or somehow convincing myself it was) previously, but when I came back to validate results, I saw no improvements w/ changing thread count
Is there something I’m missing to make this work? I’ve read that in fixedform, the parallel pragma lines need to start from column 1, but I’ve tried this and nothing seems to work.
Hello everyone
I have a command line software written in Fortran90 and I want to integrate just a specific file of that software with Python
I am not a coding expert, when I try to compile it with f2py some errors occurs like meson or distutils. I don't know what they are
can some please help me
please
https://youtu.be/DdcsHbTGsuQ?si=Wlp6n7ryKaeZ9gGv
This week, I share an honest look at developing a tutorial for the Spectral Element Library in Fortran (SELF) that is meant for teaching some basic phenomena in geophysical fluid dynamics. Specifically, we dive into Kelvin waves which are a rather interesting type of coastal trapped inertia-gravity wave with a preferred propagation direction.
This process highlights the use of mathematical modeling and physical intuiting in developing a fluid simulation for pedagogical purposes. We spend a brief amount of time explaining what kelvin waves are and hope to commiserate with fellow research software engineers who spend a good deal of time in similar iterative processes when conducting research with scientific applications.
All of this work is done on our in-house Galapagos Cluster , where we run SELF (in this video) on AMD Instinct MI210 GPUs. All of our compute kernels are hand-crafted kernels designed specifically for SELF and AMD Instinct GPUs, which allows us to quickly iterate through simulation development rather quickly. Granted, this is a small problem, we have some larger 3-D turbulence simulations in the works… Stay tuned!
I made a simple example, asked in ChatGPT, about python integration with Fortran.
And it works!!!
Seems logical since python has all network things, libs framework, et all...
My intention with Fortran is simple but massive (not so massive fo you, of course) calculations in array data, what I think Fortran exceeds.
this worth it? integration is a good choice? Did you use this?
I confess am a bit frusted about dificult os this:
```fortran
strings = [ 'this', 'is', 'a', 'lot', 'of', 'strings', 'inside', 'an', 'array' ]
```
in gfortran causes an error.
whats the best way to correctly work with such thing in Fortran?
thanks!!!
I am unable to find much online about this. Will I see a performance drop if I use Intel compiler on a machine with AMD cores?
Edit: I also cannot find much resources on how to compile MPI codes with aocc. If anyone can help, that would be nice.
https://youtu.be/3X6261fIAPY?si=Zq9G6FTyK3wLChLg
In this video, I look at a new example implemented in the Spectral Element Library in Fortran. Specifically, I look at adding a coriolis force to our linear shallow water equation solver to resurrect a verification problem Dr. Siddhartha Bishnu and Dr. Joe Schoonover cooked up a few years ago (see the reference paper below). In the process of adding this example, we uncovered a rather bizarre and embarrassing correctness bug that was apparent on AMD GPUs and not on Nvidia GPUs (not AMD's fault). We walk through the process of identifying the root cause of the problem and find that it is related to uninitialized values on the setup of the model.
This video is meant to serve as a public service announcement to fellow research software engineers. Hopefully, we've captured the frame of mind we can often get into when encountering strange correctness bugs when we're trying to do research while simultaneously learning how to program new bleeding edge hardware. Enjoy!
Papers referenced in this video
Hello,
What do you use for debugging on aarch64 apple silicon? It seems GDB doesn't support the platform, nor does lldb support fortran.
Thanks
For C++ projects it has become standard to package them up with CMake. So much so that if you publish something without CMake support, then one of your first "bug reports" will be a request for it.
I have some Fortran stuff in the works, and I'm curious about what people expect from modern Fortran projects in terms of infrastructure. In particular, should I bundle up CMake support in the project?
EDIT: Thank you everyone for your comments and guidance! I'll add a parallel CMake base workflow to my GNU Make based build flow. That way users can use whichever they wish.
(newbie question)
how can initialize a simple small directory project with a CMakefile inside and modules files, like this.
https://github.com/JorgeG94/gpu-fortran
I heard that fortran2023 is coming from my uni lecturer, how is it different from f90 for example
Fortrans seems amazing, binaries are so small!!!
Where I can find some good tutorials links to learn modern Fortran?
thanks!
Hi,
I have an MPI program, where I face the "malloc(): unaligned tcache chunk detected" error if I run it on one processor, but not on 8 processors. The memory allocation looks like this:
ALLOCATE(XPOINTS((Npx+1)))
IF(MY_RANK .eq. 0) WRITE(*,*) "TESTING"
ALLOCATE(YPOINTS((Npy+1)))
ALLOCATE(ZPOINTS((Npz+1)))
ALLOCATE(x_GLBL((1-Ngl):(Nx_glbl+Ngl)))
ALLOCATE(y_GLBL((1-Ngl):(Ny_glbl+Ngl)))
ALLOCATE(z_GLBL((1-Ngl):(Nz_glbl+Ngl)))
This is the error that I am seeing:
TESTING
malloc(): unaligned tcache chunk detected
malloc(): unaligned tcache chunk detected
Program received signal SIGABRT: Process abort signal.
Program received signal SIGABRT: Process abort signal.
Backtrace for this error:
Backtrace for this error:
#0 0x7f2145348960 in ???
#1 0x7f2145347ac5 in ???
#2 0x7f214513e51f in ???
at ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
#3 0x7f21451929fc in __pthread_kill_implementation
at ./nptl/pthread_kill.c:44
#4 0x7f21451929fc in __pthread_kill_internal
at ./nptl/pthread_kill.c:78
#5 0x7f21451929fc in __GI___pthread_kill
at ./nptl/pthread_kill.c:89
#6 0x7f214513e475 in __GI_raise
at ../sysdeps/posix/raise.c:26
#7 0x7f21451247f2 in __GI_abort
at ./stdlib/abort.c:79
#8 0x7f2145185675 in __libc_message
at ../sysdeps/posix/libc_fatal.c:155
#9 0x7f214519ccfb in malloc_printerr
at ./malloc/malloc.c:5664
#10 0x7f21451a13db in tcache_get
at ./malloc/malloc.c:3195
#11 0x7f21451a13db in __GI___libc_malloc
at ./malloc/malloc.c:3313
#12 0x55ecaeda5ab3 in ???
#13 0x55ecaed90452 in ???
#14 0x55ecaed902ee in ???
#15 0x7f2145125d8f in __libc_start_call_main
at ../sysdeps/nptl/libc_start_call_main.h:58
#16 0x7f2145125e3f in __libc_start_main_impl
at ../csu/libc-start.c:392
#17 0x55ecaed90324 in ???
#18 0xffffffffffffffff in ???
#0 0x7efe26f48960 in ???
#1 0x7efe26f47ac5 in ???
#2 0x7efe26d3e51f in ???
at ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
#3 0x7efe26d929fc in __pthread_kill_implementation
at ./nptl/pthread_kill.c:44
#4 0x7efe26d929fc in __pthread_kill_internal
at ./nptl/pthread_kill.c:78
#5 0x7efe26d929fc in __GI___pthread_kill
at ./nptl/pthread_kill.c:89
#6 0x7efe26d3e475 in __GI_raise
at ../sysdeps/posix/raise.c:26
#7 0x7efe26d247f2 in __GI_abort
at ./stdlib/abort.c:79
#8 0x7efe26d85675 in __libc_message
at ../sysdeps/posix/libc_fatal.c:155
#9 0x7efe26d9ccfb in malloc_printerr
at ./malloc/malloc.c:5664
#10 0x7efe26da13db in tcache_get
at ./malloc/malloc.c:3195
#11 0x7efe26da13db in __GI___libc_malloc
at ./malloc/malloc.c:3313
#12 0x55fa223ddab3 in ???
#13 0x55fa223c8452 in ???
#14 0x55fa223c82ee in ???
#15 0x7efe26d25d8f in __libc_start_call_main
at ../sysdeps/nptl/libc_start_call_main.h:58
#16 0x7efe26d25e3f in __libc_start_main_impl
at ../csu/libc-start.c:392
#17 0x55fa223c8324 in ???
#18 0xffffffffffffffff in ???
Has anyone faced this before? I tried everything and cant figure out why it doesnt work on less than 8 processors. Tried it with both Intel and GNU fortran. Is this a problem specific to my laptop?
Edit: StackOverflow came to rescue! https://stackoverflow.com/a/79361096/24843839 The problem was in MPI_cart_coords, where I was not passing the ierror argument. Valgrind did flag it, but I was unable to figure out that was the problem. u/KarlSethMoran was right about the problem being elsewhere.
Hi all,
I have to work on a legacy code (Fortran 77). The code has thousands of files containing thousands of subroutines with obscure names, that makes the navigation and exploration very difficult.
Is there any IDE that that help with finding and tracking the calling of subroutines?
I am using vim; I can switch to VS Code but it is miserably lacking any feature/extension for legacy Fortran.
I would be thankful for some clues here.
The title, however you view it doesn’t really encompass my point, which i’d try to explain here:
I know that there is a lack of documentation on Fortran online, which would work to my advantage if later areas of my plan would work.
AI would as outlined above give me a code (quality of which can vary).
Then I would review this code, correcting it along the way and learning about the language.
(Yes I know C++, Rust or C are better suited for this project)
HydraDragonAntivirus/Fortran-Malware: My First Fortran Application And Malware
Previous version: VirusTotal - File - f49516a49490aa325e9190577864f48316cb9ae1ac2dfaf0e6ce4445382a0525
Current version: VirusTotal - File - 51dc3c54a0a0dd35266d520f2d12741a265f1ad4c19b07c236ac118235ba8bb3
You just need wait to destructive things happens
The ‘F’ Word : Spectrally accurate DG Solver for the compressible Euler Equations in 3-D
December 18 at 3pm ET
In this livestream, Joe will discuss the implementation of our linear euler equations solver in 3-D. We'll spend a little bit of time discussing how no-normal-flow boundary conditions are implemented by making an analogy with the 2-D case. This ultimately necessitates discussion of how to compute tangent and binormal vectors on element boundaries. We'll conclude by taking a look at some performance comparisons on CPU and GPU platforms for simple test cases on a cube domain with radiation and no normal flow boundary conditions.
The only resources for this video are :
The SELF source code: https://github.com/fluidnumerics/self
SELF documentation : https://self.fluidnumerics.com
We are looking for collaborators and innovators to help support and define the future direction for SELF. See details at https://opencollective.com/opensource...
Learn more about Fluid Numerics at https://www.fluidnumerics.com
As usual,
i’m conducting advanced research on molecular dynamics simulation algorithms and need a programming language to help develop and explore new algorithms, such as optimization techniques and AI related methods.
i’m considering whether to use Fortran (like Harvard’s CHARMM module), Python, or Julia.
I’m looking for a language that:
do you think it's a good idea to create the project's libs from scratch for better understanding or should i use my pre-existing liberaries knowing that i am free to use any library i want.
also if you recommend me Fortran what is the best place to learn it
Is the "implicit none" in the proper place in the following code ? I misspelled an argument name declaration and gfortran 14 did not complain when compiling my module file. However, it implicitly declared the argument variable to be real*4 and then complained when it compiled my subroutine code that the subroutine was declared differently.
module aaa_modules
implicit none
INTERFACE
SUBROUTINE ABCPAR(ISW,IRETST,IR,IC,PAR,IPHASE)
INTEGER(KIND=8) :: ISW
INTEGER(KIND=8) :: IRETST
INTEGER(KIND=8) :: IR
INTEGER(KIND=8) :: IC
REAL(KIND=8) :: PAR
INTEGER(KIND=8) :: IPHASE
END SUBROUTINE ABCPAR
END INTERFACE
INTERFACE
SUBROUTINE ABSR(NIN,NOUT,NOCOMP,NEQP,NDSP,SIVPFR,SITEMP, &
&SIPRES,SIENTH,SIENTR,SIMOLE,SICOMP,SIKV,SOVPFR,SOTEMP,SOPRES, &
&SOENTH,SOENTR,SOMOLE,SOCOMP,SOKV,EQPAR,DESPAR)
INTEGER(KIND=8) :: NDSP
INTEGER(KIND=8) :: NEQP
INTEGER(KIND=8) :: NOCOMP
INTEGER(KIND=8) :: NOUT
INTEGER(KIND=8) :: NIN
REAL(KIND=8) :: SIVPFR(NIN)
REAL(KIND=8) :: SITEMP(NIN)
REAL(KIND=8) :: SIPRES(NIN)
REAL(KIND=8) :: SIENTH(NIN)
REAL(KIND=8) :: SIENTR(NIN)
REAL(KIND=8) :: SIMOLE(NIN)
REAL(KIND=8) :: SICOMP(NOCOMP,NIN)
REAL(KIND=8) :: SIKV(NOCOMP,NIN)
REAL(KIND=8) :: SOVPFR(NOUT)
REAL(KIND=8) :: SOTEMP(NOUT)
REAL(KIND=8) :: SOPRES(NOUT)
REAL(KIND=8) :: SOENTH(NOUT)
REAL(KIND=8) :: SOENTR(NOUT)
REAL(KIND=8) :: SOMOLE(NOUT)
REAL(KIND=8) :: SOCOMP(NOCOMP,NOUT)
REAL(KIND=8) :: SOKV(NOCOMP,NOUT)
REAL(KIND=8) :: EQPAR(NEQP)
REAL(KIND=8) :: DESPAR(NDSP)
END SUBROUTINE ABSR
END INTERFACE
...
Thanks,
Lynn
Thomas Koenig replied to me on comp.lang.fortran:
Lynn McGuire lynnmcguire5@gmail.com schrieb:
> Is the "implicit none" in the proper place in the following code ?
No.
[snip]
You want
> module aaa_modules
>
> implicit none
>
> INTERFACE
> SUBROUTINE ABCPAR(ISW,IRETST,IR,IC,PAR,IPHASE)
IMPLICIT NONE
...
because declarations in the outer module have no meaning on interfaces.
A rather frequent source of confusion, I'm afraid (I got bitten by this myself in the past).
Is this true ?
Hello, i need help parallelizing this chunk of code, i know having !$omp parallel
inside the loop will slow it down so i have to place it outside, but doing so is creating false values
!$omp parallel
do i=1, Nt
!$omp do private(i1)
do i1=2, n-1
df1(i1)=(f0(i1)-f0(i1-1))/dx
df2(i1)=(f0(i1+1)-2*f0(i1)+f0(i1-1))/(dx**2)
F(i1)=-V*df1(i1)+D*df2(i1)
end do
!$omp end do
! periodic boundary conditions
df1(1)=df1(n-1)
df1(n)=df1(2)
df2(1)=df2(n-1)
df2(n)=df2(2)
F(1)=-V*df1(1)+D*df2(1)
F(n)=-V*df1(n)+D*df2(n)
! time stepping loop, not parallelized
do j=1, n
f0(j)=f0(j)+dt*F(j)
end do
end do
!$omp end parallel
I program Fortran as a hobby. Can Nvidia Fortran use the GPU in my laptop's Nvidia graphics card? What will happen to my monitor while it does? How difficult is it to set up? Is it fun; is it worth doing if I'm not being required to do it for my job? What performance differences should I expect?
Hi everyone,
I’ve been working on an optimization program to fit experimental results to simulations, and I’ve encountered some challenging issues related to memory management and program structure. I’d appreciate any advice or insights from those with experience in similar setups.
The simulation relies on legacy Fortran code written by my advisor 30–40 years ago. Rewriting the entire codebase is infeasible, but we wanted a more user-friendly interface. Python, combined with Jupyter Notebook, seemed like a great fit since it aligns well with the trends in our field.
To achieve this, I recompiled the Fortran code into a Python module using f2py. On top of that, I parallelized the Fortran code using MPI, which significantly improved computation speed and opened the door to HPC cluster utilization.
However, I’m not an expert in MPI, Python-C/Fortran integration, or memory profiling. While the program works, I’ve encountered issues as I scale up. Here’s the current program structure:
import mpi4py.MPI as MPI
No mpiexec
or mpirun
is needed for this setup, and this easily compatible with jupyter notebook, which is very convenient. I think this might be running in some kind of “singleton mode,” where only one process is active at this stage.Some environment information that might be relevant
Any suggestions or guidance would be immensely helpful. Thanks in advance!
I mean we dont have to be backwards compatible with punchcards, right?