diff -cr espresso-3.2.2/CPV/fftdrv.f90 espresso-3.2.3/CPV/fftdrv.f90
*** espresso-3.2.2/CPV/fftdrv.f90	Mon Jun  5 12:01:46 2006
--- espresso-3.2.3/CPV/fftdrv.f90	Fri Jul 20 15:08:46 2007
***************
*** 29,35 ****
    IMPLICIT NONE
    SAVE
  
!   INTEGER, PRIVATE :: what_scatter = 1
  
  CONTAINS
  
--- 29,35 ----
    IMPLICIT NONE
    SAVE
  
!   INTEGER, PRIVATE :: what_scatter = 0
  
  CONTAINS
  
diff -cr espresso-3.2.2/ChangeLog-3.2.3 espresso-3.2.3/ChangeLog-3.2.3
*** espresso-3.2.2/ChangeLog-3.2.3	Thu May 31 15:16:27 2007
--- espresso-3.2.3/ChangeLog-3.2.3	Fri Jul 20 15:11:51 2007
***************
*** 0 ****
--- 1,23 ----
+ 31-may  PW/pwscf.f90 clib/Makefile clib/stack.c 
+ Finally found (maybe) a reliable fix for mysterious crashes with intel
+ compiler. Apparently the reason is insufficient stack size, but it may 
+ not be sufficient to use command "limits" o "ulimit", because the stack
+ size seems to be reset either by queueing systems or by the code itself.
+ A C routine that removes stack limits has been added and is called at the
+ beginning of the run.
+ 
+ 15-jun  PW/pw_restart.f90
+ Believe it or not, phonon with pools and lsda was still not working!
+ A needed correction had been forgotten in the previous patch, my fault (PG).
+ 
+ 3-jul  PH/el_opt.f90
+ The exchange-correlation contribution to the electro-optical coefficient
+ was not correct (PG)
+ 
+ 5-jul  Doc/INPUT_PP
+ Misleading documentation fixed (PG)
+ 
+ 20-jul  CPV/fftdrv.f90
+ Fixed serious cp.x bug in parallel execution if the third dimension of 
+ FFT arrays is not the same as the FFT order. May affect some calculations
+ on some machines (typically AIX with ESSL) (PG/CC)
diff -cr espresso-3.2.2/Doc/INPUT_PP espresso-3.2.3/Doc/INPUT_PP
*** espresso-3.2.2/Doc/INPUT_PP	Mon Jun  5 12:01:47 2006
--- espresso-3.2.3/Doc/INPUT_PP	Thu Jul  5 22:54:55 2007
***************
*** 44,50 ****
    !                4=local density of electronic entropy
    !                5=STM images
    !                6=spin polarization (rho(up)-rho(down))
!   !                7=|psi|^2 (See below)
    !                8=electron localization function (ELF)
    !                9=planar average of all |psi|^2
    !               10=integrated local density of states (ILDOS)
--- 44,50 ----
    !                4=local density of electronic entropy
    !                5=STM images
    !                6=spin polarization (rho(up)-rho(down))
!   !                7=|psi|^2
    !                8=electron localization function (ELF)
    !                9=planar average of all |psi|^2
    !               10=integrated local density of states (ILDOS)
***************
*** 54,100 ****
    !               12=the electric field potential
    !               13=the noncollinear magnetization.
    !
!   !
!   !     plot_num=7 in the noncollinear case, plot the contribution of the
!   !                given state to the charge or to the magnetization
!   !                along the direction indicated by spin_component
!   !                (0 = charge, 1 = x, 2 = y, 3 = z ).
!   !
!   !
!   !             Options for total charge 
    !
    ! spin_component 0=total charge (default value),
    !                1=spin up charge,
    !                2=spin down charge.
    !
!   !             Options for total potential 
    !
    ! spin_component 0=spin averaged potential (default value),
    !                1=spin up potential,
    !                2=spin down potential.
    !
!   !             Options for STM images:
    !
!   ! sample_bias    the bias of the sample (Ryd) in stm images
    ! stm_wfc_matching     if .t. match the wavefunctions to 
    !                      an exponentially vanishing function
    !                      if .t. specify also (in celldm(1) units):
    !                 z    height of matching
    !                dz    distance of next stm image calculation
    !
!   !             Options for |psi|^2:
    !
!   ! kpoint      which k-point
!   ! kband       which band
!   ! lsign       if true and k point is Gamma, save |psi|^2 sign(psi)
    !
!   !             Options for ILDOS:
    !
    ! emin        lower energy boundary (in eV)
    ! emax        upper energy boundary (in eV), i.e. compute 
    !             ILDOS from emin to emax
    !
!   !             Options for noncollinear magnetization 
    !
    ! spin_component 0=absolute value (default value)
    !                1=x component of the magnetization
--- 54,101 ----
    !               12=the electric field potential
    !               13=the noncollinear magnetization.
    !
!   !             Options for total charge (plot_num=0):
    !
    ! spin_component 0=total charge (default value),
    !                1=spin up charge,
    !                2=spin down charge.
    !
!   !             Options for total potential (plot_num=1):
    !
    ! spin_component 0=spin averaged potential (default value),
    !                1=spin up potential,
    !                2=spin down potential.
    !
!   !             Options for STM images (plot_num=5):
    !
!   ! sample_bias    the bias of the sample (Ry) in stm images
    ! stm_wfc_matching     if .t. match the wavefunctions to 
    !                      an exponentially vanishing function
+   !                      PRESENTLY DISABLED
    !                      if .t. specify also (in celldm(1) units):
    !                 z    height of matching
    !                dz    distance of next stm image calculation
    !
!   !             Options for |psi|^2 (plot_num=7):
    !
!   ! kpoint          unpolarized and noncollinear case: k-point to be plotted
!   !                 LSDA: k-point and spin polarization to be plotted
!   !                 (spin-up and spin-down correspond to different k-points!)
!   ! kband           band to be plotted
!   ! lsign           if true and k point is Gamma, save |psi|^2 sign(psi)
!   ! spin_component  noncollinear case only: plot the contribution of the
!   !                 given state to the charge or to the magnetization
!   !                 along the direction indicated by spin_component:
!   !                 0 = charge (default), 1 = x, 2 = y, 3 = z.
!   !                 Ignored in unpolarized or LSDA case
    !
!   !             Options for ILDOS (plot_num=10):
    !
    ! emin        lower energy boundary (in eV)
    ! emax        upper energy boundary (in eV), i.e. compute 
    !             ILDOS from emin to emax
    !
!   !             Options for noncollinear magnetization (plot_num=13): 
    !
    ! spin_component 0=absolute value (default value)
    !                1=x component of the magnetization
diff -cr espresso-3.2.2/Gamma/phcg.f90 espresso-3.2.3/Gamma/phcg.f90
*** espresso-3.2.2/Gamma/phcg.f90	Wed Apr 12 16:18:05 2006
--- espresso-3.2.3/Gamma/phcg.f90	Thu May 31 22:14:59 2007
***************
*** 29,34 ****
--- 29,39 ----
    LOGICAL :: exst
    INTEGER :: i
    !
+ #if defined __INTEL
+   ! ... Intel compilers v .ge.8 allocate a lot of stack space
+   ! ... Stack limit is often small, thus causing SIGSEGV and crash
+   CALL remove_stack_limit ( )
+ #endif
    !
    CALL check_stop_init () 
    !
diff -cr espresso-3.2.2/PH/el_opt.f90 espresso-3.2.3/PH/el_opt.f90
*** espresso-3.2.2/PH/el_opt.f90	Wed Apr 12 16:18:06 2006
--- espresso-3.2.3/PH/el_opt.f90	Tue Jul  3 17:33:04 2007
***************
*** 106,121 ****
       if ( rhotot.lt.-1.d-30 ) d2muxc(ir)=-d2mxc(-rhotot)
    enddo
  
- !  do ipa = 1, 3
- !     do ipb = 1, ipa
- !        do ipc = 1, ipb
    do ipa = 1, 3
       do ipb = 1, 3
          do ipc = 1, 3
             tmp = (0.d0, 0.d0)
             do ir = 1, nrxx
!               tmp = tmp + d2muxc (ir) * aux3 (1, ipa) *   &
!                         aux3 (1, ipb) * aux3 (1, ipc)
             enddo
             ps3 (ipa, ipb, ipc) =  DBLE(tmp)
          enddo
--- 106,118 ----
       if ( rhotot.lt.-1.d-30 ) d2muxc(ir)=-d2mxc(-rhotot)
    enddo
  
    do ipa = 1, 3
       do ipb = 1, 3
          do ipc = 1, 3
             tmp = (0.d0, 0.d0)
             do ir = 1, nrxx
!               tmp = tmp + d2muxc (ir) * aux3 (ir, ipa) *   &
!                        aux3 (ir, ipb) * aux3 (ir, ipc)
             enddo
             ps3 (ipa, ipb, ipc) =  DBLE(tmp)
          enddo
***************
*** 124,144 ****
  
    call DSCAL (27, omega / (nr1 * nr2 * nr3), ps3, 1)
  
- !  do ipa = 2, 3
- !     do ipb = 1, ipa-1
- !        ps3 (ipa, ipb, ipa ) = ps3 (ipa, ipa, ipb)
- !        ps3 (ipb, ipa, ipa ) = ps3 (ipa, ipa, ipb)
- !        ps3 (ipb, ipa, ipb ) = ps3 (ipa, ipb, ipb)
- !        ps3 (ipb, ipb, ipa ) = ps3 (ipa, ipb, ipb)
- !     enddo
- !  enddo
- !
- !  ps3 (1,2,3) = ps3 (3,2,1)
- !  ps3 (2,1,3) = ps3 (3,2,1)
- !  ps3 (1,3,2) = ps3 (3,2,1)
- !  ps3 (3,1,2) = ps3 (3,2,1)
- !  ps3 (2,3,1) = ps3 (3,2,1)
- 
    deallocate (d2muxc )
    deallocate (aux3   )
  #ifdef __PARA
--- 121,126 ----
diff -cr espresso-3.2.2/PH/phonon.f90 espresso-3.2.3/PH/phonon.f90
*** espresso-3.2.2/PH/phonon.f90	Thu May 31 14:58:53 2007
--- espresso-3.2.3/PH/phonon.f90	Thu May 31 21:49:08 2007
***************
*** 55,60 ****
--- 55,65 ----
    CHARACTER (LEN=256) :: auxdyn, filname, filint
    CHARACTER(LEN=6), EXTERNAL :: int_to_char
    !
+ #if defined __INTEL
+   ! ... Intel compilers v .ge.8 allocate a lot of stack space
+   ! ... Stack limit is often small, thus causing SIGSEGV and crash
+   CALL remove_stack_limit ( )
+ #endif
    !
    CALL init_clocks( .TRUE. )
    !
diff -cr espresso-3.2.2/PP/postproc.f90 espresso-3.2.3/PP/postproc.f90
*** espresso-3.2.2/PP/postproc.f90	Tue Oct 17 11:04:26 2006
--- espresso-3.2.3/PP/postproc.f90	Thu May 31 22:16:19 2007
***************
*** 27,32 ****
--- 27,38 ----
    IMPLICIT NONE
    CHARACTER(len=256) :: filplot
    !
+ #if defined __INTEL
+   ! ... Intel compilers v .ge.8 allocate a lot of stack space
+   ! ... Stack limit is often small, thus causing SIGSEGV and crash
+   CALL remove_stack_limit ( )
+ #endif
+   !
    ! initialise parallel environment
    !
    CALL start_postproc (nd_nmbr)
diff -cr espresso-3.2.2/PW/pw_restart.f90 espresso-3.2.3/PW/pw_restart.f90
*** espresso-3.2.2/PW/pw_restart.f90	Thu May 31 14:58:53 2007
--- espresso-3.2.3/PW/pw_restart.f90	Fri Jun 15 18:42:52 2007
***************
*** 2427,2433 ****
           IF ( nspin == 2 ) THEN
              !
              ispin = 1 
!             isk(ik) = 1
              !
              IF ( ionode ) THEN
                 !
--- 2427,2435 ----
           IF ( nspin == 2 ) THEN
              !
              ispin = 1 
!             ! ... no need to read isk here: they are read from band structure
!             ! ... and correctly distributed across pools in read_file
!             !!! isk(ik) = 1
              !
              IF ( ionode ) THEN
                 !
***************
*** 2447,2453 ****
              !
              ispin = 2
              ik_eff = ik + num_k_points
!             isk(ik_eff) = 2
              !
              IF ( ionode ) THEN
                 !
--- 2449,2456 ----
              !
              ispin = 2
              ik_eff = ik + num_k_points
!             ! ... no need to read isk here (see above why)
!             !isk(ik_eff) = 2
              !
              IF ( ionode ) THEN
                 !
***************
*** 2467,2473 ****
              !
           ELSE
              !
!             isk(ik) = 1
              !
              IF ( noncolin ) THEN
                 !
--- 2470,2477 ----
              !
           ELSE
              !
!             ! ... no need to read isk here (see above why)
!             !isk(ik) = 1
              !
              IF ( noncolin ) THEN
                 !
diff -cr espresso-3.2.2/PW/pwscf.f90 espresso-3.2.3/PW/pwscf.f90
*** espresso-3.2.2/PW/pwscf.f90	Wed Jun  7 09:47:13 2006
--- espresso-3.2.3/PW/pwscf.f90	Thu May 31 15:11:32 2007
***************
*** 31,36 ****
--- 31,41 ----
    !
    CHARACTER (LEN=9) :: code = 'PWSCF'
    !
+ #if defined __INTEL
+   ! ... Intel compilers v .ge.8 allocate a lot of stack space
+   ! ... Stack limit is often small, thus causing SIGSEGV and crash
+   CALL remove_stack_limit ( )
+ #endif
    !
    ! ... use ".FALSE." to disable all clocks except the total cpu time clock
    ! ... use ".TRUE."  to enable clocks
diff -cr espresso-3.2.2/clib/Makefile espresso-3.2.3/clib/Makefile
*** espresso-3.2.2/clib/Makefile	Mon Mar  5 15:24:40 2007
--- espresso-3.2.3/clib/Makefile	Thu May 31 15:12:25 2007
***************
*** 3,8 ****
--- 3,9 ----
  include ../make.sys
  
  OBJS = \
+ stack.o \
  c_mkdir.o \
  cptimer.o \
  fft_stick.o \
***************
*** 20,25 ****
  	co -l $(OBJS:.o=.c)
  
  clean :
! 	- rm -f clib.a *.o *.mod *.i core* *.L
  
  include make.depend
--- 21,26 ----
  	co -l $(OBJS:.o=.c)
  
  clean :
! 	- rm -f clib.a *.o *.mod *.i core*
  
  include make.depend
diff -cr espresso-3.2.2/clib/stack.c espresso-3.2.3/clib/stack.c
*** espresso-3.2.2/clib/stack.c	Thu May 31 15:16:35 2007
--- espresso-3.2.3/clib/stack.c	Thu Jul  5 22:33:44 2007
***************
*** 0 ****
--- 1,22 ----
+ /*
+   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 ) {
+     perror("Cannot set stack size to infinity");
+     /* exit(1); */
+   }
+ }
