0

I have tried the pyipopt to run IPOPT. That works well.

But I am using Fortran 90 now. I look into the example hs071_f in IPOPT for the Fortran interface. I guess it is written in Fortran 77? Unfortunately, I really don't understand.

I was wondering whether there was a Fortran 90 interface?

Though I just found a Fortran90 Interface Source from http://apmonitor.com/wiki/index.php/Main/DownloadIpopt, I cannot build it. Is it because I am using Mac but the source is for Windows?

Errors:

gfortran hs071.f90 -o vfi.out -fbounds-check -O2
Undefined symbols for architecture x86_64:
"_ipaddintoption_", referenced from:
_MAIN__ in cculABQh.o
"_ipaddnumoption_", referenced from:
_MAIN__ in cculABQh.o
"_ipaddstroption_", referenced from:
_MAIN__ in cculABQh.o
"_ipcreate_", referenced from:
_MAIN__ in cculABQh.o
"_ipfree_", referenced from:
_MAIN__ in cculABQh.o
"_ipopenoutputfile_", referenced from:
_MAIN__ in cculABQh.o
"_ipsolve_", referenced from:
_MAIN__ in cculABQh.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Looking forward to anyone's advice! Thanks in advance!

zz273
  • 17
  • 5
  • If it is only an interface, you have to link the original library too! – Vladimir F Героям слава Jan 26 '20 at 19:27
  • Hi Vladimir, thank you for your comment. May I ask what "link" means? Sorry that I am still very new to Fortran. Any simple example or resource is appreciated. – zz273 Jan 26 '20 at 20:34
  • https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix I can't tell you your command, because I have no idea how you installed or at least unpacked the IPOPT library. But you typically compile all necessary source files into object files using the `-c` option and then you "link" all the object files in a single `gfortran` (or similar) command. If your library is pre-compiled in a dynamic library, you use the `-l` option. – Vladimir F Героям слава Jan 26 '20 at 21:28
  • Thanks, Vladimir. I will try it! – zz273 Jan 26 '20 at 23:06
  • I would suggest consulting the IPOPT documentation: https://coin-or.github.io/Ipopt/INSTALL.html and https://coin-or.github.io/Ipopt/INTERFACES.html. The C++ interface section has some clues, among other things it says that after downloading the IPOPT library you will be able to find a folder with examples and that folder contains a makefile. In the makefile you will be able to find a compiler line. Perhaps, there will be a Fortran version as well but even if it weren't, you should get a good idea from the C++ version. – PetrH Jan 27 '20 at 11:56
  • Hi PetrH, thank you for your comment. The problem is that I don't know C++ nor Fortran 77 for the examples. But it seems like I have to learn. Thanks again! – zz273 Jan 27 '20 at 18:07
  • @zz273 That was not the point of my comment, you do not need to know C++ to read the explanation in the docs. The point was that there is an example makefile that you can use and adapt. That make file has little to do with C++ and most likely there is a fortran version as well. It is the linking part that you are looking for and that is independent of the Fortran version. – PetrH Jan 28 '20 at 16:37
  • Thank you @PetrH for your advice. I tried `gfortran hs071.f90 -o hs071.out -L /usr/local/lib -lipopt -fbounds-check -O2`, and no errors. But when I run `./hs071.out`, some errors show up: ```Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x108d0d3ed #1 0x108d0c87b #2 0x7fff61daeb5c #3 0x108aed668 #4 0x108ad1b9d #5 0x108ad24de Segmentation fault: 11 ``` I really don't know how to deal with it next. Do you have any advice? Thanks a lot! – zz273 Feb 01 '20 at 04:49
  • @zz273 Segmentation fault is a run-time error, seems like it compiled and linked the library fine but there may be a bug in your code. Perhaps you use the interface incorrectly or the problem may not be related to the ipopt library at all. Adding these flags to your compiler options may help you narrow down where the segfault occurs. `-g -Wall -fcheck=all` – PetrH Feb 01 '20 at 12:01
  • Thank you @PetrH for the advice of the flag. I tried and received some warnings all similar to `Warning: Unused dummy argument 'dat' at (1) [-Wunused-dummy-argument]` Do you think this is the reason why I cannot execute successfully? Thank you! – zz273 Feb 06 '20 at 17:09
  • @zz273 Probably not, a segmentation fault is typically caused by events like writing in an allocatable array which has not been allocated or writing more elements than the array's size. Still, it would be a good idea to fix all these warnings first. Then, I would suggest that you narrow the segfault down to where roughly in your code the problem occurs. Another simple strategy to locate the problem would be to add a couple of `print` statements and see after/before which of those the programme crashed. Once you have an idea, ask a new question showing the relevant parts of the code. – PetrH Feb 07 '20 at 13:51
  • Thank you @PetrH for your advice. I ask a new question and a nice person tells me that I need to correct `integer` into `integer*8` for the 64-bit library. And it works. Thanks again! – zz273 Feb 08 '20 at 15:58

0 Answers0