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

ERROR when using LCONF and L2ONF

Nga_N_
Beginner
1,375 Views

Hello,

I would like to ask for help.

When running a program using LCONF and L2ONF, I encountered an ERROR:

ERROR 5 FROM LCONF.  The equality constraints and the bounds on the variables are found to be inconsistent.

I checked the program with Matlab and there was no feasible solution. 

I use LCONF in a loop for 12 cases. It worked well with the first 8 cases and there was above ERROR with 9th case (I knew that this case does not have optimal solution). When encountering the ERROR, the program crashed and stopped working at case 9th. Hence, case 10th, 11th,12th will not be run.

Would you please let me know how I can make the program keep working with case 10th, 11th, 12th without stopping because of ERROR of case 9th?

Thank you so much.

0 Kudos
1 Solution
mecej4
Honored Contributor III
1,375 Views

In the IMSL MATH Library manual, after Chapter 11 there is a chapter called Reference Material. Read the documentation on Subroutine ERSET and Function IERCD. These routines will help you to change the default action after a terminal error is encountered, and to retrieve information on error codes set by IMSL.

View solution in original post

0 Kudos
13 Replies
mecej4
Honored Contributor III
1,376 Views

In the IMSL MATH Library manual, after Chapter 11 there is a chapter called Reference Material. Read the documentation on Subroutine ERSET and Function IERCD. These routines will help you to change the default action after a terminal error is encountered, and to retrieve information on error codes set by IMSL.

0 Kudos
Nga_N_
Beginner
1,375 Views

To mecej4:

Thank you so much for your help! The program works well with ERSET.

Thanks a lot :)

Bests,

 

0 Kudos
Nga_N_
Beginner
1,375 Views

To mecej4:

I have one more question, would you please kindly help?

If case 9 has no solution, I use CALL ERSET (0, 1, 0) to skip the error and continue with the remaining cases. When I export the optimal result for all cases to a .txt file, I still see the result of case 9 (unfeasible solution). Would you please show me how I can print out a notification such as "No solution" for case 9 instead of printing out the unfeasible solution? Or is there any flag that show that there is not any solution for this case? If there is, I can use this flag to print out the notification.

Thank you so  much.

0 Kudos
mecej4
Honored Contributor III
1,375 Views

I do not quite understand the difficulty. By setting IPRINT, which is an argument to L2ONF, you control the output of intermediate and final results from this (and other IMSL routines that have IPRINT as an argument). In many applications, it is perfectly normal to request IMSL to do no printing at all, and do your own output before and after the call to the IMSL routine. If IMSl fails to solve a particular case, you can find out from the INFO value the reason for the failure, and you can print whatever is appropriate. If, in the LCONF example code in the IMSL manual, you change 72.0 to -72.0, the constraints become inconsistent and, if you have not called ERSET, an error message is printed after running the code. If you call ERSET(0,0,0), the program terminates with no output from IMSL.

If you chose to print intermediate results (by using 1 as the second argument to ERSET), and IMSL detects a problem after printing some intermediate results, then you will have some useless output lines in the log file.  Is this what you see? 

A simple tactic to handle this case is to get IMSl output to go to a scratch file which is opened for each case that you run. If a case succeeds, you append the contents of the scratch file to your cumulative log file and, if a case fails, you do nothing and move on to the next case, if any.

0 Kudos
Nga_N_
Beginner
1,375 Views

I am using LCONF because I have not figured out how to use L2ONF which has INFO.

Would you please send me a sample program for L2ONF?  I tried to replace LCONF with L2ONF but it did not work. 

0 Kudos
mecej4
Honored Contributor III
1,375 Views

Nga N. wrote:

I am using LCONF because I have not figured out how to use L2ONF which has INFO.

Would you please send me a sample program for L2ONF?  I tried to replace LCONF with L2ONF but it did not work. 

Please post the code that "did not work". I do not have an example of calling L2ONF available.

Have you tried calling ERSET(0,0,0) instead of ERSET(0,1,0)?

0 Kudos
Nga_N_
Beginner
1,375 Views

This is a sample code that I used to try  L2ONF. It gave the same error with my big program which I used 12 loops. My big program also did not work due to the same errors. Would you please help me to check the error?

INCLUDE 'link_fnl_shared.h'
Program DeltaS

      USE LCONF_INT
      !USE UMACH_INT
 
      IMPLICIT   NONE
!                                 Declaration of variables
      INTEGER    NCON, NEQ, NVAR
      PARAMETER  (NCON=2, NEQ=0, NVAR=3)
!
      INTEGER    MAXFCN, NOUT
      REAL       A(NCON,NVAR), ACC, B(NCON), OBJ, &
                SOL(NVAR), XGUESS(NVAR), XLB(NVAR), XUB(NVAR)
       INTEGER :: NACT, IACT(NCON + 2 * NVAR),  IPRINT, INFO, LDA  
       REAL  :: ALAMDA(NVAR), WK(NVAR**2 + 11 * NVAR + NCON)   
      
      EXTERNAL   FCN
     
      
      DATA A/-1.0, 1.0, -2.0, 2.0, -2.0, 2.0/, B/0.0, 72.0/
      DATA XLB/3*0.0/, XUB/20.0, 11.0, 42.0/, XGUESS/3*10.0/
      DATA ACC/0.0/, MAXFCN/400/

      CALL L2ONF (FCN, NVAR, NCON, NEQ, A, LDA, B, XLB, XUB, XGUESS, ACC, MAXFCN, SOL, OBJ, NACT, IACT, ALAMDA, IPRINT, INFO, WK)
       PRINT  * , '', SOL
       PRINT  * , '', OBJ
      PAUSE
      
       END program DeltaS
!
      SUBROUTINE FCN (N, X, F)
      INTEGER    N
      REAL       X(*), F
!
      F = -X(1)*X(2)*X(3)
      RETURN
      ENDSUBROUTINE FCN 

0 Kudos
mecej4
Honored Contributor III
1,375 Views

You should have "LDA=NCON" before the call to L2ONF.

Similarly, other input arguments such as IPRINT should be assigned values before the call. The program may still produce correct results despite such errors, but on one fine day the same program may fail.

0 Kudos
Nga_N_
Beginner
1,375 Views

With the same code, if I use " XUB/20.0, 2.0, 42.0/,'" instead of  XUB/20.0, 11.0, 42.0/  to make an inconsistency in the  boundaries, (the upper bound is smaller than lower bound), why the program still gives a result with INFO =1?   It should show an error and INFO should be 5 or 6 or 7.

My purpose is to make an error in the program so that it give me the INFO of the error.

0 Kudos
mecej4
Honored Contributor III
1,375 Views

Nga N. wrote:

With the same code, if I use " XUB/20.0, 2.0, 42.0/,'" instead of  XUB/20.0, 11.0, 42.0/  to make an inconsistency in the  boundaries, (the upper bound is smaller than lower bound), ...

You specified XLB(2) = 0, so setting XUB(2)=2.0 did not introduce any inconsistency. Try setting XUB(2) to -2, and run again.

0 Kudos
Nga_N_
Beginner
1,375 Views

I am sorry about that. It should be -2. 

I have the error (9) and I want to run the following code to write a notification to a .txt file:

CALL ERSET (0, 1, 0)  

OPEN (80,FILE='result.txt',status='unknown')  

 IF (INFO == 9) THEN

WRITE(80,*) 'No solution'

ENDIF

I was not able to write anything in the .txt file  (even if I put CALL ERSET (0, 1, 0)  after ENDIF  or  delete CALL ERSET (0, 1, 0) ). Would you please recommend any solution?

0 Kudos
mecej4
Honored Contributor III
1,375 Views

You have to read the IMSL documentation carefully and try a few runs to see how the IMSL routines behave when a solution fails. That behavior can be different depending on whether IMSL can detect if the input arguments are incorrect, or some calculations have to be performed before it gives up on obtaining a solution. 

The following code attempts three cases. The first two are solved normally. The third fails because the bounds are inconsistent. The code checks for such failures, and copies the results from the IMSL output file to the user output file after each successful run, but skips the copying when a run has failed.

Program DeltaS

      USE LCONF_INT

      IMPLICIT   NONE
      INTEGER    NCON, NEQ, NVAR, IRUN
      PARAMETER  (NCON=2, NEQ=0, NVAR=3)
!
      INTEGER    MAXFCN, NOUT, IERCD, N1RTY
      REAL       A(NCON,NVAR), ACC, B(NCON), OBJ, &
                SOL(NVAR), XGUESS(NVAR), XLB(NVAR), XUB(NVAR)
      INTEGER :: NACT, IACT(NCON + 2 * NVAR),  IPRINT, INFO, LDA
      REAL  :: ALAMDA(NVAR), WK(NVAR**2 + 11 * NVAR + NCON)
      CHARACTER(100) :: STR

      EXTERNAL   FCN


      DATA A/-1.0, 1.0, -2.0, 2.0, -2.0, 2.0/, B/0.0, 72.0/
      DATA XLB/3*0.0/, XUB/20.0, 2.0, 42.0/, XGUESS/3*10.0/
      DATA ACC/0.0/

      LDA=NCON
      IPRINT=1
      ACC=1d-8
      CALL ERSET(0,1,0)
      CALL UMACH(-2,11)
      CALL UMACH(-3,12)
      OPEN (UNIT=10,FILE='RESULTS.TXT',STATUS='REPLACE')
      OPEN (UNIT=11,FILE='LCONF.OUT',STATUS='REPLACE')
      OPEN (UNIT=12,FILE='LCONF.ERR',STATUS='REPLACE')
      WRITE(*,*)'         RUN        INFO         IERCD     N1RTY'
      DO IRUN = 1,3
         XUB(2) = XUB(2) - 0.7
         MAXFCN = 10
         CALL L2ONF (FCN, NVAR, NCON, NEQ, A, LDA, B, &
            XLB, XUB, XGUESS, ACC, MAXFCN, SOL, OBJ,  &
            NACT, IACT, ALAMDA, IPRINT, INFO, WK)
         WRITE(10, 50)'RUN ',IRUN,'  INFO = ',INFO,'  IERCD = ', &
                     IERCD(),'  N1RTY = ',N1RTY(1)
   50 format(1X,A,I4,A,I4,A,I4,A,I4)
         IF (N1RTY(1) .EQ. 1) THEN
            REWIND(11)
            DO
               READ(11,'(A)', END=100)STR
               WRITE(10,'(A)')STR
            END DO
         ELSE
            WRITE(10,'(A,I3,A)')' RUN ',IRUN,' FAILED, NO OUTPUT'
         ENDIF
  100 CONTINUE
         REWIND(11)
         PRINT *,IRUN,INFO,IERCD(),N1RTY(1)
      END DO
      CLOSE(10)
      CLOSE(11)
      CLOSE(12)
      END program DeltaS
!
      SUBROUTINE FCN (N, X, F)
      INTEGER    N
      REAL       X(*), F
!
      F = -X(1)*X(2)*X(3)
      RETURN
      END SUBROUTINE FCN

Here is the console output from the program.

          RUN        INFO         IERCD     N1RTY
           1           1           1           1
           2           1           1           1
           3           1           0           5

 

0 Kudos
Nga_N_
Beginner
1,375 Views

Thank you so much for helping me out. This is really what I want. I changed my code following your code and it works well now. I am just a beginner in Fortran and I don't completely understand all the details in the IMSL documentation (especially some parts that do not have the sample codes).

Thank you so much for your patience.

0 Kudos
Reply