In this section, we explain how to program OmniRPC in FORTRAN. If you want to know more details about APIs, see Section FORTRAN API .
main.f: double precision a(10),b(10),r do i = 1,10 a(i) = i b(i) = i+10 end do call innerprod(10,a,b,r) write(*,*) 'result=',r end ip.f: subroutine innerprod(n,a,b,r) integer n double precision a(*),b(*),r integer i r = 0.0 do i = 1,n r = r+a(i)*b(i) end do return end
Let's set this program to call the innerprod subroutine with OmniRPC.
As in a C program, we create a program which executes a subroutine on remote hosts. So, we define an interface to innerprod. We set the module name as f_innerprod, and the function name as innerprod.
Module f_innerprod; Define innerprod(IN int n, IN double a[n], IN double b[n], OUT double result[1]) Calls "Fortran" innerprod_(n,a,b,result);
The argument which specifies the array size must be a scalar variable. The double precision type in FORTRAN is "double", the real type is "float". If you directly call a FORTRAN function with calls, you specify "Fortran". Calling a function can mangle the function name in FORTRAN. Usually, in the case of the FORTRAN compiler, a mangled name is a name to which "_" has been added. Please pay attention to whether a function name contains "_"; if it is mangled, add "__" in g77 (gcc).
This definition is the same as the above definition. As scalar variable is taken as the address pointer.
Module f_innerprod; Define innerprod(IN int n, IN double a[n], IN double b[n], OUT double result[1]) { innerprod_(&n,a,b,result); }
Generate OmniRPC's remote executable modules from this IDL file. We name this IDL file f_ip.idl.
$ omrpc-fc f_ip.idl ip.f
When you run this command, the remote executable program f_ip.rex is generated. To register with omrpc-register, the method is the same as in C language.
$ omrpc-register -register f_ip.rex
The command omrpc-fc, it compiles FORTRAN program with f77. If you want to use another compiler, use the "-fc" option. For example, if you want to use the intel Fortran compiler of ifc, run the following command.
$ omrpc-fc -fc ifc f_ip.idl ip.f
And now, change the client program main.f to call the remote executable program with OmniRPC.
double precision a(10),b(10),r call OMINRPC_INIT do i = 1,10 a(i) = i b(i) = i+10 end do call OMNIRPC_CALL("f_innerprod*",10,a,b,r) write(*,*) 'result=',r call OMNIRPC_FINALIZE end
This program initializes with OMNIRPC_INIT and calls by OMNIRPC_CALL. Please keep in mind that the entry name which is specified by OMNIRPC_CALL should have "*" at the end of the name which is defined on the interface. You should add "*" to the end of strings which are obtained with OmniRPC, such as the module name and host name. OmniRPC considers "*" to be a string terminator in OmniRPC's Fortran API.
Using omrpc-fc to compile this file.
$ omrpc-fc main.f
Finally, we show an example which is written in FORTRAN. this example is also shown in the section Parallel programming with OmniRPC .
double precision res(10) double precision x integer ireqs(10) call omnirpc_init x = 0.0 do i = 1, 10 call omnirpc_call_async(ireqs(i),'calc_sin*',x,res(i)) x = x + 1.0 end do call omnirpc_wait_all(10,ireqs) do i = 1, 10 write(*,*) 'res(',i, ')=',res(i) end do call omnirpc_finalize endFor API details, see Fortran API .