EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
objective_gradient.f90
Go to the documentation of this file.
1 subroutine objective_gradient(n,x,g)
2 implicit none
3 integer, parameter :: rk = kind(1.0d0)
4 integer, intent(in) :: n
5 real(kind=rk), dimension(n), intent(in) :: x
6 real(kind=rk), dimension(n), intent(out) :: g
7 
8 real(kind=rk), dimension(2) :: fullx
9 integer :: mpi_rank,mpi_err
10 include 'mpif.h'
11 integer :: status(mpi_status_size)
12 
13 ! Rosenbrock function gradient
14 call mpi_comm_rank(mpi_comm_world,mpi_rank,mpi_err)
15 
16 select case(mpi_rank)
17 case(0)
18  fullx(1) = x(1)
19  call mpi_send(fullx(1),1,mpi_double_precision,1,1,mpi_comm_world&
20  &,mpi_err)
21  call mpi_recv(fullx(2),1,mpi_double_precision,1,1,mpi_comm_world&
22  &,status,mpi_err)
23  g(1) = 200*(fullx(2) - fullx(1)**2)*(-2*fullx(1)) - 2*(1 - fullx(1))
24 case(1)
25  fullx(2) = x(1)
26  call mpi_recv(fullx(1),1,mpi_double_precision,0,1,mpi_comm_world&
27  &,status,mpi_err)
28  call mpi_send(fullx(2),1,mpi_double_precision,0,1,mpi_comm_world&
29  &,mpi_err)
30  g(1) = 200*(fullx(2) - fullx(1)**2)
31 case default
32  print*,'too many processes launched for the model. Error'
33  stop
34 end select
35 
36 
37 
38 end subroutine objective_gradient
subroutine objective_gradient(n, x, g)