Software Archive
Read-only legacy content
17060 Discussions

use-host assoiation

rahzan
New Contributor I
993 Views
I need to run an optimization algorithm but the fucntion which returns the value to optimize is use-host associated with the routine which calls the optimizer like this:


main: 
get necessary data & parameters to evaluate function 
call optimzer 
CONTAINS 
function func 
calculate with data shared by use-host assoc from main 
end func 
end main 
 
subroutine optimizer 
... 
call func 
... 
end optimizer 


I know that I read in the doc that though not standard, CVF does support exporting the use-host routines externally, but the above scheme does not link saying that the func call in Optimizer is unresolved.

Can this really be done? if so how?
moreover, Can the optimizer everbe put in a module and still call a func not inside it?

Thanks, Tim
0 Kudos
2 Replies
Steven_L_Intel1
Employee
993 Views
In your case, func is not visible at all outside main. Now if main were a module and func was a module procedure, optimizer could USE the module and call func.

The other thing you could do is something like this:


program main
call sub (func)
contains
integer function func (i)
func = i + 1
return
end function func
end
subroutine sub (func)
integer, external :: func
write (*,*) func(3)
return
end


In this case, you must make sure that the function is called with exactly the number of arguments it expects. (Your sample CALLed a function, which is a no-no.)

The above is non-standard, but CVF supports it.

I hope this helps.

Steve
0 Kudos
rahzan
New Contributor I
993 Views
Thanks Steve,
This was a dum q to start, of course the second metod you show should be obvious, as I realized after posting the msg.
Sorry!
Tim
0 Kudos
Reply