[Pw_forum] segmentation fault -stack -gfortran (ambavale sagar)

Cesar R.S. da Silva cesards at msi.umn.edu
Sun Jul 6 00:37:40 CEST 2008


Dear Ambavale,


Some time ago I posted a suggestion for a small improvement in stack.c that
would prevent the segmentation fault error in many situations.

At the time, my suggestion was dismissed as irrelevant as the only effect
of the sloppy code should be the generation of an annoying message. For
the record, the only thing I agree is that the message is really annoying.

The code in v4.x tries to set the stack as unlimited, if it fails it tries
to set to 1.0 GB. However, some systems have a maximum limit for the
stack. 1.0 GB is a lot of stack, and is also very likely to exceed the
maximum limit. So, the code is still as sloppy as it was before the last
revisions.

My fix is to set the stack to the maximum allowed by the system, if
unlimited fails. It is eventually still insufficient but, as far as I
know, there is nothing better to do within user level programming to
further increase the stack. If setting to the maximum allowed is not
enough, You can, at compile time, make espresso to allocate local vars in
the heap. This  can cause the heap to become fragmented, but is not as bad
as not running at all.

If there is a lesson to be taken, it is: Never use a sloppy code unless
the fix us unfeasible, no matter how inconsequential it seems to be.

Well, I am using the following code for stack.c and it is working so far.

Yours,

Cesar R.S. da Silva.


***************************************************************************
/*
  Copyright (C) 2007 Quantum-Espresso group
  This file is distributed under the terms of the
  GNU General Public License. See the file `License'
  in the root directory of the present distribution,
  or http://www.gnu.org/copyleft/gpl.txt .
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include "c_defs.h"

void F77_FUNC(remove_stack_limit,REMOVE_STACK_LIMIT) (void) {

  struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY };

  if ( setrlimit(RLIMIT_STACK, &rlim) == -1 ) {
    if ( getrlimit(RLIMIT_STACK, &rlim) == 0 ) {
      rlim.rlim_cur = rlim.rlim_max;
      if ( setrlimit(RLIMIT_STACK, &rlim) == 0 ) {
        getrlimit(RLIMIT_STACK, &rlim);
      } else {
        perror("  Cannot set stack size to new value");
      }
    }

  }
}

***************************************************************************





> ------------------------------
>
> Message: 5
> Date: Sat, 5 Jul 2008 17:34:37 +0530 (IST)
> From: ambavale sagar <sagarambavale at yahoo.co.in>
> Subject: [Pw_forum] segmentation fault -stack -gfortran
> To: pwforum que-ans <pw_forum at pwscf.org>
> Message-ID: <233418.16134.qm at web94607.mail.in2.yahoo.com>
> Content-Type: text/plain; charset="utf-8"
>
> hi all,
> I am running conduction calculations of linear chain comprising of '3
> carbons and 2 silicons placed alternate' using pwcond.x of espresso-4.0
> compiled with LAM-MPI, ifort10.1 on double cpu Quad-core xeon machine
> which gives me "forrtl: severe (174): SIGSEGV, segmentation fault
> occurred". {For chain of 3 Carbons and 1 Si it didn't gave error. } Manual
> of ifort says "This message indicates that the program attempted an
> invalid memory reference. Check the program for possible errors." Is this
> related to stack limit? But for that ifort should write error message
> like:" severe (174): SIGSEGV, possible program stack overflow occurred"
> ?
> Moreover i read in ../Doc/changelog-4.0 that C subroutine named 'stack.c'
> is called in the starting of program to remove(?) the stack limit imposed
> by ifort. Where should i make change to increase the stack limit to 4gb?
> Moreover, i think there is one '}' is missing... if i uncomment the
> portion that defines Axel's version (1 gb).
> ?
> ?P.S.: In ifort manual i found one variable called "KMP_STACKSIZE".{Sets
> the number of bytes to allocate for each OpenMP* thread to use as the
> private stack for the thread.
> Recommended size is 16m.??? Use the optional suffixes: b (bytes), k
> (kilobytes), m (megabytes), g (gigabytes), or t (terabytes) to specify the
> units.?? This variable does not affect the native operating system threads
> created by the user program nor the thread executing the sequential part
> of an OpenMP* program or parallel programs created using -parallel (Linux
> and Mac OS X) or /Qparallel (Windows).}
> ?How to set this variable?
> One more question:
> ?
> When i configured espresso with gfortran (version 4.1)giving:
> ../configure --disable-parallel F90=gfortran CC=gcc
> LAPACK_LIBS="~/espresso-4.0/flib/lapack.a" BLAS_LIBS="
> ~/espresso-4.0/flib/blas.a" DFLAGS=-D__USE_INTERNAL_FFTW
> It gave the error at the time of compilation :
> ?REAL(DP),?? allocatable :: of_r(:,:)? ! the charge density in R-space
> ?????????????????????????? 1
> Error: Attribute at (1) is not allowed in a TYPE definition
> ?In file scf_mod.f90:49
> ?
> ???? COMPLEX(DP),allocatable :: of_g(:,:)? ! the charge density in G-space
> ?????????????????????????? 1
> Error: Attribute at (1) is not allowed in a TYPE definition
> ?In file scf_mod.f90:50
> ............
> ..........
> ........
> make[1]: *** [scf_mod.o] Error 1
> make[1]: Leaving directory `/home/sagar/espresso-4.0/PW'
> make: *** [pw] Error 2
> [sagar at localhost espresso-4.0]$
> ?
> ?
> Sagar Ambavale
> Phd student
> The M.S. University of Baroda
> India
>
>
>       Explore your hobbies and interests. Go to
> http://in.promos.yahoo.com/groups/
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://www.democritos.it/pipermail/pw_forum/attachments/20080705/54437581/attachment.htm
>
> ------------------------------
>





More information about the users mailing list