program main
use mpi
use pFIO
use server_demo_CLI
use FakeExtDataMod_server
use MAPL_ExceptionHandling
implicit none
integer :: rank, npes, ierror, provided
integer :: status, color, key, rc
class(BaseServer),allocatable :: s
type (CommandLineOptions) :: options
integer, parameter :: SERVER_COLOR = 1
integer, parameter :: CLIENT_COLOR = 2
integer :: comm
!C$ integer :: num_threads
type (FakeExtData), target :: extData
class(AbstractDirectoryService), pointer :: d_s=>null()
call MPI_init_thread(MPI_THREAD_MULTIPLE, provided, ierror)
_VERIFY(ierror)
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror)
_VERIFY(ierror)
call MPI_Comm_size(MPI_COMM_WORLD, npes, ierror)
_VERIFY(ierror)
call process_command_line(options, rc=status)
if (rank < options%npes_server) then
color = SERVER_COLOR
else
color = CLIENT_COLOR
end if
key = 0
call MPI_Comm_split(MPI_COMM_WORLD, color, key, comm, ierror)
_VERIFY(ierror)
!C$ num_threads = 20
allocate(d_s, source = DirectoryService(MPI_COMM_WORLD))
if (color == SERVER_COLOR) then
if(trim(options%server_type) == 'mpi') then
allocate(s, source=MpiServer(comm, 'i_server'))
call d_s%publish(PortInfo('i_server', s),s)
call d_s%connect_to_client('i_server', s)
print*, "using MpiServer"
else if(trim(options%server_type) == 'openmp') then
!C$ call omp_set_num_threads(num_threads)
!C$ allocate(s, source=OpenMPServer(comm,d_s))
!C$ print*, "using OpenMPServer"
else
print*, options%server_type // ' not implemented'
stop
endif
call s%start()
else ! client
call extData%init(options, comm, d_s)
call extData%run(step=1)
call extData%run(step=2)
call extData%finalize()
!print*,"terminate_servers"
!call global_directory_service%terminate_servers(comm)
end if
call MPI_finalize(ierror)
end program main