- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Hi all,
in our MPI C(++)/Fortran mixed code project (Linux x64 and Windows x64) MySQL is partly used in the C-part to transfer data between master and slave process. Now it is necessary also to connect some Fortran-slave parts to MySQL.
One solution could be to use only C to connect to MySQL and push the data to Fortran over the interface. This solution is not nice because it will blow up the interface in a way which makes it prone to errors and debugging won't be easy.
The second solution could be to use the mysql.f90 wrapper out of FLIBS (http://flibs.cvs.sourceforge.net/viewvc/flibs/, many thanks to Daniel Kraft and arjenmarkus). In this point I'm stuck because I am not familiar with the use of pointers in iso_c_binding and the necessay declation of data types in the Fortran part from where I make the call.
For example, the connection function to a MySQL service out of mysql.f90 says:
FUNCTION c_connect (mysql, host, user, pwd, db, port, socket, flags) &
BIND(C, NAME='mysql_real_connect')
USE ISO_C_BINDING
IMPLICIT NONE
TYPE(C_PTR) :: c_connect
TYPE(C_PTR), VALUE :: mysql
CHARACTER(C_CHAR), DIMENSION(*) :: host, user, pwd, db
INTEGER(C_INT), VALUE :: port
TYPE(C_PTR), VALUE :: socket
INTEGER(C_INT), VALUE :: flags
END FUNCTION c_connect
How do I call this function from my Fortran main code and how have the parameters to be declared there?
character(len=80) :: host, user, pwd, db
integer(kind=4) :: port, flags
type(c_ptr) :: mysql, socket
type(c_ptr) :: MySQLConRet
... assign variables ...
MySQLConRet = c_connect(mysql, host, user, pwd, db, port, socket, flags)
This was my not working approach.
I've read this http://software.intel.com/en-us/forums/topic/280611 and http://software.intel.com/en-us/forums/topic/289724 , but unluckily the attachments cannot be downloaded anymore, so that the examples are lost.
Any help will be welcome :-)
Kind regards, Johannes
コピーされたリンク
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
If I limit the character pointer in the write statement to
[fortran]write(*,*) 'MySQL Connection Info: ', t0dumy_ptr(1:20)[/fortran]
then I will get the correct message in the console window: MySQL Connection Info: 127.0.0.1 via TCP/IP Very curious... Johannes
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
c_string_ptr = c_get_host_info(myf%mysql) call c_f_pointer(c_string_ptr, t0dummy_ptr) ! ,shape(c_string_ptr) i = INDEX(t0dummy_ptr, ACHAR(0)) mysql_get_host_info = t0dummy_ptr(1:(i-1)) END FUNCTION mysql_get_host_info [/fortran] In this way I can work with the result as a normal fortran character. The original library (libmysql.lib -> libmysql.dll) is from the C API delivered with MySQL and delivers a char* in the native C(++)-code, the C-call is: [cpp] const char* c_textdummy; c_textdummy = mysql_get_host_info(MySQLConnection); // or printf("MySQL Connection Info: %s \n", mysql_get_host_info(MySQLConnection)); [/cpp] Nevertheless, the character(c_char) seems to contain still the NULLs from c and if I want to use it in Fortran I have to split them at the NULLs or curous things will happen. Kind regards, Johannes
