IPC with named pipes: reviving legacy code

111 views Asked by At

I am developing a code in Fortran2003 that depends in an essential way on the output of a large, sophisticated, and very efficient legacy program written in Fortran77. For the future development of the new project, it would be useful for the legacy program not to pass the data by generating large files before the new program starts, but rather to provide data on demand, in real time, based on queries from the new program. Of all the various IPC mechanisms that I have seen, it looks like named pipes would be the easiest to implement, which can be done using Fortran intrinsic features, and that it would also be decently fast (certainly much faster than communicating through real files!)

I tested the idea with two executables that open the same fifo in stream access, and it looks like it works fine:

program Proc1

  implicit none

  character(len=*), parameter :: DATA_FIFO ="data.fifo"
  integer            :: i, data_uid
  integer, parameter :: N = 100000000
  real(kind(1d0))    :: mat(N)

  open(newunit=data_uid,file=DATA_FIFO,access="stream")
  mat=1.d0
  write(*,*) "sending data",sum(mat)
  write(data_uid) (mat(i),i=1,N)
  close(data_uid)

end program Proc1
program Proc2
  
  implicit none

  character(len=*), parameter :: DATA_FIFO ="data.fifo"
  integer            :: i, data_uid
  integer, parameter :: N = 100000000
  real(kind(1d0))    :: mat(N)

  open(newunit=data_uid,file=DATA_FIFO,access="stream")
  read(data_uid) (mat(i),i=1,N)
  write(*,*)"data received", sum(mat)
  close(data_uid)

end program Proc2

In the real case, I would modify the legacy code to make it a "demon" capable of listening to an instruction pipe, and reading / writing information to data pipes opened with the new program. When the new program will scale to distributed memory, each node could have its own demon. Before going ahead, however, I would like to have feedback on whether this scheme is a valid idea at all. If the answer is positive, are there standard implementations for this problem (namely, IPC between legacy Fortran code converted ad-hoc to a server, and a new fortran code that is supposed to go parallel)? If the answer is negative, what would be a more valid solution that can be general enough without becoming very complex (memory sharing looks tricky to me)? Thank you very much for your thoughts.

0

There are 0 answers