- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I need to use the LCONF from the IMSL library to solve an optimization problem. The subroutine that computes the function values contains some input arguments. I do not know how to pass these parameter values when using LCONF.
Because I also want to use MPI or OpenMP, I want to limit the use of modules or common blocks, which may create conflict in the memory. That is, the parameters I want to use in the function varies in the program. When I parallelize the code, each processor should be able to update and use its own parameters in that function.
In the help, FCN is the user-supplied subroutine to evaluate the function to be minimized. The usage is CALL FCN (N, X, F), where
!=====CODE=========
program main
USE LCONF_INT
USE UMACH_INT
INCLUDE 'link_fnl_static.h'
!DEC$ OBJCOMMENT LIB:'libiomp5md.lib'
IMPLICIT NONE
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), X(NVAR)
EXTERNAL FCN
REAL para, F
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 UMACH (2, NOUT)
para = 1.0
X=2.0
CALL FCN (NVAR, X, F, para)
CALL LCONF (FCN, NEQ, A, B, XLB, XUB, SOL, XGUESS=XGUESS, MAXFCN=MAXFCN, ACC=ACC, OBJ=OBJ)
END
SUBROUTINE FCN (N, X, F, para)
INTEGER N
REAL X(*), F, para
F = -(X(1)-para)*X(2)*X(3)
END
I need to use the LCONF from the IMSL library to solve an optimization problem. The subroutine that computes the function values contains some input arguments. I do not know how to pass these parameter values when using LCONF.
Because I also want to use MPI or OpenMP, I want to limit the use of modules or common blocks, which may create conflict in the memory. That is, the parameters I want to use in the function varies in the program. When I parallelize the code, each processor should be able to update and use its own parameters in that function.
In the help, FCN is the user-supplied subroutine to evaluate the function to be minimized. The usage is CALL FCN (N, X, F), where
N Value of NVAR. (Input)
X Vector of
length
N at
which point
the function is evaluated. (Input)
X should not be
changed by FCN.
F The computed function value at the point X. (Output)
However, the function I want to minimize will be in the following form: CALL FCN(N,X,F,para). where para is a vector of length NP which is also an input for the function.
Can someone let me know what I should do if I want to minimize such kind of functions? A sample code is below which is adapted from the example with just FCN(N,X,F) in the IMSL mannual. I got error messages on this code. Thank you very much.
!=====CODE=========
program main
USE LCONF_INT
USE UMACH_INT
INCLUDE 'link_fnl_static.h'
!DEC$ OBJCOMMENT LIB:'libiomp5md.lib'
IMPLICIT NONE
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), X(NVAR)
EXTERNAL FCN
REAL para, F
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 UMACH (2, NOUT)
para = 1.0
X=2.0
CALL FCN (NVAR, X, F, para)
CALL LCONF (FCN, NEQ, A, B, XLB, XUB, SOL, XGUESS=XGUESS, MAXFCN=MAXFCN, ACC=ACC, OBJ=OBJ)
END
SUBROUTINE FCN (N, X, F, para)
INTEGER N
REAL X(*), F, para
F = -(X(1)-para)*X(2)*X(3)
END
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
LCONF doesn't provide a way to supply an extra argument. An approach you can take is to make FCN an CONTAINed function, which gives it access to its host's local variables. Something like this:
[fortran]program main USE LCONF_INT USE UMACH_INT INCLUDE 'link_fnl_static.h' !DEC$ OBJCOMMENT LIB:'libiomp5md.lib' IMPLICIT NONE 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), X(NVAR) REAL para, F 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 UMACH (2, NOUT) para = 1.0 X=2.0 CALL FCN (NVAR, X, F) CALL LCONF (FCN, NEQ, A, B, XLB, XUB, SOL, XGUESS=XGUESS, MAXFCN=MAXFCN, ACC=ACC, OBJ=OBJ) CONTAINS SUBROUTINE FCN (N, X, F) INTEGER N REAL X(*), F F = -(X(1)-para)*X(2)*X(3) END SUBROUTINE FCN END[/fortran]
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can pass "para" via common block or module.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry I wasn't clear. Because I also want to use MPI or OpenMP, I want to limit the use of modules or common blocks, which may create conflict in the memory. That is, the parameters I want to use in the function varies in the program. When I parallelize the code, each processor should be able to update and use its own parameters in that function. Any further suggestion? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
LCONF doesn't provide a way to supply an extra argument. An approach you can take is to make FCN an CONTAINed function, which gives it access to its host's local variables. Something like this:
[fortran]program main USE LCONF_INT USE UMACH_INT INCLUDE 'link_fnl_static.h' !DEC$ OBJCOMMENT LIB:'libiomp5md.lib' IMPLICIT NONE 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), X(NVAR) REAL para, F 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 UMACH (2, NOUT) para = 1.0 X=2.0 CALL FCN (NVAR, X, F) CALL LCONF (FCN, NEQ, A, B, XLB, XUB, SOL, XGUESS=XGUESS, MAXFCN=MAXFCN, ACC=ACC, OBJ=OBJ) CONTAINS SUBROUTINE FCN (N, X, F) INTEGER N REAL X(*), F F = -(X(1)-para)*X(2)*X(3) END SUBROUTINE FCN END[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
Thank you very much. Your suggestion is very helpful.
Thank you very much. Your suggestion is very helpful.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page