Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28991 Discussions

Error: Stack around the variable 'x' was corrupted.

matsumoto__noriyuki
1,249 Views

Dear Experts,

Thank you for your time to see this post. First of all, I am not a software professional, but have been using Fortran with IMSL for my data analysis for years. I appreciate your understandings if descriptions below may not make senses from professional point of view.

I had been using the Visual Fortran 9.1 with the Visual Studio 2005 until my Windows PC was changed to the latest corporate Windows version. Until that time, the source code I paste below actually worked. Upon the Windows PC change, I also changed the Fortran version to XE 2013 with the Visual Studio 2010. With this compiler, the same source code became not working. The compiling process and linking process work, however, when I run it, I always get the error in the subject. More specifically, even I get this error, if I keep pressing "Continue" button on the dialog, I can get proper computation results. The biggest problem is that probably due to this warning (or error), I cannot get an execuatable to distriburte to other computers.

The code below is the subroutine to perform a surface fitting using the IMSL libraries. With this code, the first error I get is (the 'x' in the subject is), "nmiss". Just for trial, if I declare interger*8 nmiss, x will change to "nobs". Similarly, "nInd", "ldX" then "nRow". After this x will becomde "tol", then I have no idea what to do next.

Your help will be much appreciated, for resolving this issue and any adiveces for improving my code.

Best regards,

Nori
 

c     ------------------------------------------------------------
      subroutine Fitting(PorT,acqDat,dF1,dF2,coef,nComb)
c     ------------------------------------------------------------
 
      Parameter(ido=0,nVar=64,ifrq=0,iwt=0,mopt=0,
     &          icopt=1,ldCov=64,ldincd=1)
      Parameter(intercep=1,nDep=1,ldB=64,ldR=64,ldscpe=1)

 real*8 acqDat(nComb),dF1(nComb),dF2(nComb)
 real*8 X(nComb,nVar),xmean(nVar),Cov(nVar,nVar)
 real*8 B(nVar,nDep),R(nVar,nVar),coef(9,9)
 real*8 tol

      integer incd(1,1),nComb
 character PorT*1

     
 nRow=nComb
 ldx =nComb

 nInd=nVar-intercep
 tol=1.0d0*dmach(4)

 do iRow=1,ldX
   i=1
   do n1=1,8
    do n2=1,8
      if(n1.ne.1.or.n2.ne.1)then
        X(iRow,i)=(dF2(iRow)**(n2-1))*(dF1(iRow)**(n1-1)) 
       i=i+1
      endif
    end do
   end do
   X(iRow,i)=acqDat(iRow)
 end do

 call dcorvc(ido,nRow,nVar,X,ldX,ifrq,iwt,mopt,icopt,xmean,Cov,
     &            ldCov,incd,ldincd,nobs,nmiss,sumwtf)
 call drcov(intercep,nInd,nDep,Cov,ldCov,xmean,sumwtf,tol,
     &           B,ldB,R,ldR,irank,scpe,ldscpe)

 do n1=1,8
   do n2=1,8
  coef(n1,n2)=0.0d0
   end do
 end do

 j=0
 do n1=1,8
   do n2=1,8
   j=j+1
   coef(n1,n2)=B(j,nDep)
   end do
 end do
 return
 end

 

0 Kudos
4 Replies
mecej4
Honored Contributor III
1,249 Views

I think that the most probable reason for the errors is that several of the real type arguments to the IMSL routines dcorvc and drcov are required to be double precision but, because you did not declare the variables as such, are single precision reals under the Fortran implicit typing rules. Such errors would definitely cause the call to IMSL to fail. Similarly, you have to declare the function dmach to be double precision.

It may be that the program is running out of stack space on the new system. You have four 2-D local arrays in the subroutine which may become quite large for some values of the argument ncomb. What was the value of this argument in your run?

You may be able to solve the problem by using the /heap-arrays:nn compiler option. Alternatively, you can raise the stack size by using the option /link /F:nn. With both the options that I mentioned, you need to specify a suitable number in place of nn.

You ask for trouble by making arbitrary changes to IMSL subroutine argument types. such as changing the type of nmiss to integer*8. Do not make such changes.

If you still have runtime errors, please submit a complete example code that generates or reads the arguments that are passed to your subroutine, so that we can try to reproduce the error.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,249 Views

When you get the dialog box with the Continue button, with that box in focus, press and hold the Alt key, then press Print Screen key, then release both keys. Next launch Windows Paint (it is in the Accessories section), in Paint, press Ctrl-V (or you can do Edit, Paste). This will place a copy of the image of the dialog box into Paint, save this to a file, then upload the file here. If that is too much for you to follow then type in a facsimile of the dialog box in your message.

Jim Dempsey

0 Kudos
mecej4
Honored Contributor III
1,249 Views

Matsumoto-san:

Here is a fixed-up version of your subroutine. I added a main program to call the subroutine with random "data", and removed the post-processing that you do after the call to DRCOV. I had to do some adjustment to the X matrix to make its upper square part positive definite. You would have to remove this adjustment when you use your real data.

Note that I have added IMPLICIT NONE and I have declared all the variables used. Specifically,  DCORVC/DRCOV take no single precision real arguments.

 

program datafit
implicit none
integer, parameter :: ncomb=100
double precision, dimension(ncomb) :: acqDat,dF1,dF2
!
call random_number(acqdat)  ! random data for testing subroutine
call random_number(dF1)
call random_number(dF2)
call Fitting(acqdat,dF1,dF2,ncomb)
!
end program datafit
!
!     ------------------------------------------------------------
      subroutine Fitting(acqDat,dF1,dF2,nComb)
!     ------------------------------------------------------------

 USE corvc_int
 USE RCOV_int
 implicit none
 integer ido,nvar,ifrq,iwt,mopt,icopt,ldcov,ldincd,intercep,ndep
 integer ldb,ldr,ldscpe,ncomb
      Parameter(ido=0,nVar=64,ifrq=0,iwt=0,mopt=0,   &
               icopt=1,ldCov=64,ldincd=1)
      Parameter(intercep=1,nDep=1,ldB=64,ldR=64,ldscpe=1)

 real*8 acqDat(nComb),dF1(nComb),dF2(nComb)
 real*8 X(nComb,nVar),xmean(nVar),Cov(nVar,nVar)
 real*8 B(nVar,nDep),R(nVar,nVar)
 real*8 tol,dmach,scpe,sumwtf

      integer incd(1,1)
 integer nrow,ldx,nind,irow,i,n1,n2,j,nobs,nmiss,irank


 nRow=nComb
 ldx =nComb

 nInd=nVar-intercep
 tol=1.0d0*dmach(4)

 do iRow=1,ldX
   i=1
   do n1=1,8
    do n2=1,8
      if(n1.ne.1.or.n2.ne.1)then
        X(iRow,i)=(dF2(iRow)**(n2-1))*(dF1(iRow)**(n1-1))
       i=i+1
      endif
    end do
   end do
   X(iRow,i)=acqDat(iRow)
 end do
 do i=1,min(ncomb,nvar)
   X(i,i) = 10*X(i,i) ! help make matrix +def
 end do
 call dcorvc(ido,nRow,nVar,X,ldX,ifrq,iwt,mopt,icopt,xmean,Cov, &
     &            ldCov,incd,ldincd,nobs,nmiss,sumwtf)
 call drcov(intercep,nInd,nDep,Cov,ldCov,xmean,sumwtf,tol, &
     &           B,ldB,R,ldR,irank,scpe,ldscpe)
 write(*,77)B
 77 format(5ES12.4,/,5ES12.4,/)
 return
 end

 

0 Kudos
matsumoto__noriyuki
1,249 Views

Dear all,

Thank you very much for your kind advices and suggestions. I actually could resolve the problem --  it was indeed due to improper type declarations. Once I explicitly declare all the integer and real types, the symptom disappeard. I realize it was not due to the new compiler but due to the improper souce codes, which was somehow accpepted by previous compilers.

I also thank other useful suggestions such as the stack size change and suggestions for improving my code. I will try how it will work later.

I just wanted to tell that the problem is gone, thanks to your help.

Hope you have a nice day.

Best regards,

Nori.

0 Kudos
Reply