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 8902189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:33:01+00:00 2026-06-15T01:33:01+00:00

When I try to parallelize my program in Fortran90 by OpenMP, I get a

  • 0

When I try to parallelize my program in Fortran90 by OpenMP, I get a segmentation fault error.

    !$OMP PARALLEL DO NUM_THREADS(4) &
    !$OMP PRIVATE(numstrain, i)
    do irep = 1, nrep
        do i=1, 10
            PRINT *, numstrain(i)
        end do
    end do
    !$OMP END PARALLEL DO

I find that if I comment out “PRINT *, numstrain(i)” or remove openmp flags it works without error. I think it is because memory access conflict happens when I access numstrain(i) in parallel. I already declared i and numstrain as private variables. Could someone please give me some idea why it is the case? Thank you so much. 🙂

UPDATE:

I modified the previous version and this version can print out correct result.

integer, allocatable :: numstrain(:)
integer :: allocate_status
integer :: n
!$OMP PARALLEL DO NUM_THREADS(4) &
!$OMP PRIVATE(numstrain, i)
n = 1000000
do irep = 1, nrep
    allocate (numstrain(n), stat = allocate_status)
    do i=1, 10
        PRINT *, numstrain(i)
    end do
    deallocate (numstrain, stat = allocate_status)
end do
!$OMP END PARALLEL DO

However if I move the numstrain accessing to another subroutine called by this subroutine (code attached below), 1. It always processes in one thread. 2. At some point (i=4 or 5), it returns Segmentation Fault:11. The variable i when it returns Segmentation Fault:11 is different when I have different NUM_THREADS.

integer, allocatable :: numstrain(:)
integer :: allocate_status
integer :: n
!$OMP PARALLEL DO NUM_THREADS(4) &
!$OMP PRIVATE(numstrain, i)
n = 1000000
do irep = 1, nrep
    allocate (numstrain(n), stat = allocate_status)
    call anotherSubroutine(numstrain)
    deallocate (numstrain, stat = allocate_status)
end do
!$OMP END PARALLEL DO

subroutine anotherSubroutine(numstrain)
    integer, allocatable   :: numstrain(:)
    do i=1, 10
        PRINT *, numstrain(i)
    end do
end subroutine anotherSubroutine

I also tried to both allocate/deallocate in help subroutine and main subroutine, and only allocate/deallocate in help subroutine. Nothing is changed.

  • 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-15T01:33:02+00:00Added an answer on June 15, 2026 at 1:33 am

    The most typical reason for this is that not enough space is available on the stack to hold the private copy of numstrain. Compute and compare the following two values:

    • the size of the array in bytes
    • the stack size limit

    There are two kinds of stack size limits. The stack size of the main thread is controlled by things like process limits on Unix systems (use ulimit -s to check and modify this limit) or is fixed at link time on Windows (recompilation or binary edit of the executable is necessary in order to change the limit). The stack size of the additional OpenMP threads is controlled by environment variables like the standard OMP_STACKSIZE, or the implementation-specific GOMP_STACKSIZE (GNU/GCC OpenMP) and KMP_STACKSIZE (Intel OpenMP).

    Note that most Fortran OpenMP implementations always put private arrays on the stack, no matter if you enable compiler options that allocate large arrays on the heap (tested with GNU’s gfortran and Intel’s ifort).

    If you comment out the PRINT statement, you effectively remove the reference to numstrain and the compiler is free to optimise it out, e.g. it could simply not make a private copy of numstrain, thus the stack limit is not exceeded.


    After the additional information that you’ve provided one can conclude, that stack size is not the culprit. When dealing with private ALLOCATABLE arrays, you should know that:

    • private copies of unallocated arrays remain unallocated;
    • private copies of allocated arrays are allocated with the same bounds.

    If you do not use numstrain outside of the parallel region, it is fine to do what you’ve done in your first case, but with some modifications:

    integer, allocatable :: numstrain(:)
    integer :: allocate_status
    integer, parameter :: n = 1000000
    interface
       subroutine anotherSubroutine(numstrain)
          integer, allocatable :: numstrain(:)
       end subroutine anotherSubroutine
    end interface
    
    !$OMP PARALLEL NUM_THREADS(4) PRIVATE(numstrain, allocate_status)
    allocate (numstrain(n), stat = allocate_status)
    !$OMP DO
    do irep = 1, nrep
       call anotherSubroutine(numstrain)
    end do
    !$OMP END DO
    deallocate (numstrain)
    !$OMP END PARALLEL
    

    If you also use numstrain outside of the parallel region, then the allocation and deallocation go outside:

    allocate (numstrain(n), stat = allocate_status)
    !$OMP PARALLEL DO NUM_THREADS(4) PRIVATE(numstrain)
    do irep = 1, nrep
       call anotherSubroutine(numstrain)
    end do
    !$OMP END PARALLEL DO
    deallocate (numstrain)
    

    You should also know that when you call a routine that takes an ALLOCATABLE array as argument, you have to provide an explicit interface for that routine. You can either write an INTERFACE block or you can put the called routine in a module and then USE that module – both cases would provide the explicit interface. If you do not provide the explicit interface, the compiler would not pass the array correctly and the subroutine would fail to access its content.

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

Sidebar

Related Questions

I am using gcc's implementation of openmp to try to parallelize a program. Basically
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
I have a program using OpenMP to parallelize a for-loop. Inside the loop, the
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
Try as I might I cannot get my head around what the IteratorIterator class
I have a program which I'm trying to get to work as fast as
Try to use npm install libxml and an error : Failed at the libxml@0.0.5
I have written a small test program in which I try to use the
Hallo Everyone, I am actually on topic of 3d-Scanning for robotic pick&place-applications. To get
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]

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.