Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:21:46+00:00 2026-06-08T23:21:46+00:00

I have a Fortran numerical code that calls a subroutine from an external module.

  • 0

I have a Fortran numerical code that calls a subroutine from an external module. This code has been running fine for me until I tried to compile and run on a different machine. On the new machine, my program crashes fairly quickly.

Using debug print statements, I have isolated that the crash occurs on return from the external subroutine. The main program calls the subroutine several times, and the crash occurs on return from the second call to the subroutine (the first call works fine). It always crashes on the second subroutine call with this set of input data, but with another set of input data (roughly 1/3 the size of the first), it crashes on return from the fifth subroutine call.

The symptoms suggest to me that something is getting stored in memory each time and accumulates over each subroutine call until it runs out of space, but I’m not sure what that is or how that would occur. The code is hard to simplify to a minimal working example, but I have posted the relevant portion below. Let me know if there is something else that would be helpful to see. It is basically fixed form Fortran 90.

         use fd

         implicit none

         integer, parameter :: ms = 2000
         integer n
         real(dp), dimension(ms) :: s
         real(dp), dimension(ms) :: e
         real(dp), dimension(ms) :: f
         real(dp), dimension(ms) :: d1f
         real(dp), dimension(ms) :: d2f
         real(dp), dimension(ms) :: c, d
         real(dp), dimension(ms) :: a
         real(dp), dimension(ms) :: b
         real(dp), dimension(ms) :: temp
         integer w
         integer k
         real(dp) th

         do i = 1,n
           temp(i) = a(i)
         end do
         call lprsmf(s(1:n),temp(1:n),n,w,k,th,a(1:n),d1f(1:n),
      *               d2f(1:n))

         do i = 1,n
           temp(i) = b(i)
         end do
         call lprsmf(s(1:n),temp(1:n),n,w,k,th,b(1:n),d1f(1:n),
      *               d2f(1:n))

         do i = 1,n
           temp(i) = c(i)
         end do
         call lprsmf(s(1:n),temp(1:n),n,w,k,th,c(1:n),d1f(1:n),
      *               d2f(1:n))

         do i = 1,n
           temp(i) = d(i)
         end do
         call lprsmf(s(1:n),temp(1:n),n,w,k,th,d(1:n),d1f(1:n),
      *               d2f(1:n))

         do i = 1,n
           temp(i) = e(i)
         end do
         call lprsmf(s(1:n),temp(1:n),n,w,k,th,e(1:n),d1f(1:n),
      *               d2f(1:n))

         do i = 1,n
           temp(i) = f(i)
         end do
         call lprsmf(s(1:n),temp(1:n),n,w,k,th,f(1:n),d1f(1:n),
      *               d2f(1:n))

module fd:

      module fd
        ! Double precision real kind
        integer, parameter :: dp = selected_real_kind(15)

      contains

      subroutine lprsmf(x,y,n,w,k,th,s,d1,d2)
!       INPUTS:
!         x, y, n, w, k, th
!       OUTPUTS:
!         s, d1, d2

        implicit none

        real(dp), dimension(n) :: x,y,s,d1,d2
        integer n,w,k
        real(dp) th

!     ... code here ...

      end subroutine lprsmf

      end module fd

My compiler is gfortran 4.6.1. Besides getting the code to stop crashing, I really would like to understand what is fundamentally going on with the argument passing (as I assume the problem lies with the array slices being passed out of the program). Note that a,b,c,d,e,f,s,temp,d1f,d2f have length 2000, while n, which represents the range of valid data, is in the range 100-500, depending on the input data length.

EDIT: The error message is Windows putting up a dialog informing me that the program has stopped working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:21:49+00:00Added an answer on June 8, 2026 at 11:21 pm

    Thanks to all for the help in chasing down this problem. I followed M.S.B.’s suggestion and compiled with -O2 -fimplicit-none -Wall -Wline-truncation -Wcharacter-truncation -Wsurprising -Waliasing -Wimplicit-interface -Wunused-parameter -fwhole-file -fcheck=all -fbacktrace. This revealed a memory leak in someone else’s older F77 code I had included in my subroutine. Apparently some internal arrays were declared with a length 1 item shorter than needed. I fixed that, and everything seems to work fine now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple piece of code that extracts a float from a FORTRAN-generated
I have to convert some code from Fortran so doesn't know how what this
I have a fortran code build that uses cmake to build. This is currently
I have a FORTRAN 95 program that needs to make some calls to the
I very rarely use fortran, however I have been tasked with taking legacy code
Good practice dictates that subroutine arguments in Fortran should each have a specified intent
I've been starting to use Fortran (95) for some numerical code (generating python modules).
I have some Fortran 77 source files that I'm trying to convert from a
Today I was reading code from some very popular numerical libraries written in FORTRAN
I have a library that contains a significant amount of fortran code in it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.