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

  • Home
  • SEARCH
  • 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 8774933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:41:19+00:00 2026-06-13T18:41:19+00:00

Thank you for having a look at this problem. Problem: seg. fault when returning

  • 0

Thank you for having a look at this problem.

Problem:
seg. fault when returning from f90 subroutine that contains KINSOL solving process, after the correct computation result has been generated. No problem when the same solving process is in the main program.

Environment:
linux,
gcc,
sundials static libs

How to initiate the problem:

get the attached REDUCED test code

module moduleNonlinearSolve
  integer,save::nEq
contains
  subroutine solveNonlinear(u)
    double precision::u(*)
    integer iout(15),ier
    double precision rout(2),koefScal(nEq)
    koefScal(:)=1d0
    call fnvinits(3,nEq,ier)
    call fkinmalloc(iout,rout,ier)
    call fkinspgmr(50,10,ier)
    call fkinsol(u,1,koefScal,koefScal,ier)
    call fkinfree()
    do i=1,nEq
      write(*,*),i,u(i)
    end do
  end subroutine
end module

subroutine fkfun(u,fval,ier)
  use moduleNonlinearSolve
  double precision::u(*)
  double precision::fval(*)
  integer::ier
  forall(i=2:nEq-1)
    fval(i)=-u(i-1)+2d0*u(i)-u(i+1)-1d0
  end forall
  fval(1)=u(1)+2d0*u(1)-u(2)-1d0
  fval(nEq)=-u(nEq-1)+2d0*u(nEq)+u(nEq)-1d0
  ier=0
end subroutine

program test
  use moduleNonLinearSolve
  double precision u(10)
  nEq=size(u)
  u(:)=10d0
  call solveNonlinear(u)
end program``

compile

$ gfortran -c -Wall -g test.f90
$ gfortran -Wall -g -o test test.o -lsundials_fkinsol -lsundials_fnvecserial -lsundials_kinsol -lsundials_nvecserial -llapack -lblas

run

$ ./test

Note: It would work flawlessly if put all the SUNDIALS procedures in the main program.

Thank you very much for any input.

Mianzhi

  • 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-13T18:41:21+00:00Added an answer on June 13, 2026 at 6:41 pm

    According to the KINSOL documentation, the first argument of fkinmalloc must be of the same integer type as the C type long int. In your case, long int is 8 bytes long, but you are passing in an array of 4 byte integers. This will lead to fkinmalloc trying to write beyond the bounds of the array, and into some other memory. This typically leads to memory corruption, which has symptoms just like what you are observing: Crash at some random later point, such as when returning from a function. You should be able to confirm this by running the program through valgrind, which will probably report invalid writes of size 8. Anyway, replacing

    integer :: iout(15)
    

    with

    integer*8 :: iout(15)
    

    should solve the problem.

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

Sidebar

Related Questions

OK. Thank you for giving me your precious time to look over this problem.
I am having a problem with my jquery form. If you look at this
After having this problem: look I checked some things: When going into my virtualenv
I think I am having a problem with the scope of 'this' when needing
This is related to this post . I think I am having problem with
Im having this problem only with IE8 it even works well on IE6!!... Im
thank you for taking time to look at this. I am trying to code
I'm having this problem and I didnt find any answers on the web. I
I ran into this problem today, haven't been having an issue. Any suggestions where
I'm having a problem with this query for some reason: $this->db->query(UPDATE schools SET name

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.