psmile_enddef_msg_inters_utils.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! Copyright 2010, DKRZ, Hamburg, Germany.
00003 ! All rights reserved. Use is subject to OASIS4 license terms.
00004 !-----------------------------------------------------------------------
00005 !
00006 ! !DESCRIPTION:
00007 !
00008 ! This file contains routines for initiating objects of the derived
00009 ! type enddef_msg_intersections. In addition there are two routines
00010 ! which allow to convert between object from this type and a integer
00011 ! array which is sendable via MPI.
00012 ! Since objects of type enddef_msg_intersections have a dynamical
00013 ! size it seems unpractically for me to create a MPI datatype for
00014 ! sending these objects.
00015 !
00016 !
00017 ! !REVISION HISTORY:
00018 !
00019 !   Date      Programmer   Description
00020 ! ----------  ----------   -----------
00021 ! 25.11.10    M. Hanke     created
00022 !
00023 !----------------------------------------------------------------------
00024 !
00025 !  $Id: psmile_enddef_msg_inters_utils.F90 2792 2010-12-01 17:35:05Z hanke $
00026 !  $Author: hanke $
00027 !
00028 !----------------------------------------------------------------------
00029 
00030 subroutine psmile_init_enddef_msg_inters (msg_intersections)
00031    use psmile_common, only : enddef_msg_intersections, &
00032                              psmile_undef
00033 
00034    implicit none
00035 
00036    type (enddef_msg_intersections), intent (out) :: msg_intersections
00037 
00038    msg_intersections%tgt_comp_id                   = psmile_undef
00039    msg_intersections%src_comp_id                   = psmile_undef
00040    msg_intersections%tgt_grid_id                   = psmile_undef
00041    msg_intersections%src_grid_id                   = psmile_undef
00042    msg_intersections%first_tgt_all_extents_grid_id = psmile_undef
00043    msg_intersections%first_src_all_extents_grid_id = psmile_undef
00044    msg_intersections%first_tgt_method_id           = psmile_undef
00045    msg_intersections%method_type                   = psmile_undef
00046    msg_intersections%method_datatype               = psmile_undef
00047    msg_intersections%all_comp_infos_comp_idx       = psmile_undef
00048    msg_intersections%first_tgt_var_id              = psmile_undef
00049    msg_intersections%tgt_mask_id                   = psmile_undef
00050    msg_intersections%transient_in_id               = psmile_undef
00051    msg_intersections%transient_out_id              = psmile_undef
00052    msg_intersections%num_vars                      = psmile_undef
00053    msg_intersections%num_parts                     = psmile_undef
00054    msg_intersections%relative_msg_tag              = psmile_undef
00055    msg_intersections%requires_conserv_remap        = psmile_undef
00056 
00057    nullify (msg_intersections%intersections)
00058 
00059 end subroutine psmile_init_enddef_msg_inters
00060 
00061 subroutine psmile_pack_msg_intersections (msg_intersections, buffer)
00062    use psmile_common, only : enddef_msg_intersections, ndim_3d, &
00063                              ip_msgint_inter, nd_msgint, psmile_undef 
00064 
00065    implicit none
00066 
00067    type (enddef_msg_intersections), intent (in) :: msg_intersections
00068    integer, intent (out)                        :: buffer(nd_msgint)
00069 
00070    integer :: npart, offset, n
00071 
00072    buffer = psmile_undef
00073 
00074    buffer  (1) = msg_intersections%src_comp_id
00075    buffer  (2) = msg_intersections%first_src_all_extents_grid_id
00076    buffer  (3) = msg_intersections%tgt_comp_id
00077    buffer  (4) = msg_intersections%tgt_grid_id
00078    buffer  (5) = msg_intersections%first_tgt_all_extents_grid_id
00079    buffer  (6) = msg_intersections%first_tgt_method_id
00080    buffer  (7) = msg_intersections%method_type
00081    buffer  (8) = msg_intersections%method_datatype
00082    buffer  (9) = msg_intersections%all_comp_infos_comp_idx
00083    buffer (10) = msg_intersections%first_tgt_var_id
00084    buffer (11) = msg_intersections%tgt_mask_id
00085    buffer (12) = msg_intersections%transient_in_id
00086    buffer (13) = msg_intersections%num_parts
00087    buffer (14) = msg_intersections%transient_out_id
00088    buffer (15) = msg_intersections%num_vars
00089    buffer (16) = msg_intersections%requires_conserv_remap
00090    buffer (17) = msg_intersections%relative_msg_tag
00091 
00092    npart = msg_intersections%num_parts
00093 
00094    if (npart > 0) then
00095 
00096       do n = 1, npart
00097          buffer (ip_msgint_inter+1+(n-1)*2*ndim_3d:ip_msgint_inter+n*2*ndim_3d) = &
00098                pack (msg_intersections%intersections(n)%intersection, .true.)
00099       enddo
00100 
00101       buffer (ip_msgint_inter+2*ndim_3d*npart+1:ip_msgint_inter+2*ndim_3d*npart+npart) = &
00102          msg_intersections%intersections(1:npart)%tgt_all_extents_grid_id
00103 
00104       buffer (ip_msgint_inter+2*ndim_3d*npart+npart+1:ip_msgint_inter+2*ndim_3d*npart+2*npart) = &
00105          msg_intersections%intersections(1:npart)%src_all_extents_grid_id
00106 
00107       ! if there is additional data for gridless grids
00108       if (npart < size (msg_intersections%intersections)) then
00109 
00110          buffer(ip_msgint_inter+2*ndim_3d*npart+2*npart+1) = msg_intersections%num_parts
00111 
00112          do n = 1, size (msg_intersections%intersections) - npart
00113 
00114             buffer(ip_msgint_inter+2*ndim_3d*npart+2*npart+2+(n-1)*2*ndim_3d: &
00115                    ip_msgint_inter+2*ndim_3d*npart+2*npart+1+n*2*ndim_3d) =   &
00116                pack (msg_intersections%intersections(n+npart)%intersection, .true.)
00117          enddo
00118       endif
00119    endif
00120 end subroutine psmile_pack_msg_intersections
00121 
00122 subroutine psmile_unpack_msg_intersections (msg_intersections, buffer)
00123    use psmile_common, only : enddef_msg_intersections, ndim_3d, &
00124                              ip_msgint_inter, nd_msgint, psmile_undef
00125 
00126    implicit none
00127 
00128    type (enddef_msg_intersections), intent (out) :: msg_intersections
00129    integer, intent (in)                          :: buffer(nd_msgint)
00130 
00131    integer :: n, npart, npart_alloc
00132 
00133    msg_intersections%src_comp_id                   = buffer  (1)
00134    msg_intersections%first_src_all_extents_grid_id = buffer  (2)
00135    msg_intersections%tgt_comp_id                   = buffer  (3)
00136    msg_intersections%tgt_grid_id                   = buffer  (4)
00137    msg_intersections%first_tgt_all_extents_grid_id = buffer  (5)
00138    msg_intersections%first_tgt_method_id           = buffer  (6)
00139    msg_intersections%method_type                   = buffer  (7)
00140    msg_intersections%method_datatype               = buffer  (8)
00141    msg_intersections%all_comp_infos_comp_idx       = buffer  (9)
00142    msg_intersections%first_tgt_var_id              = buffer (10)
00143    msg_intersections%tgt_mask_id                   = buffer (11)
00144    msg_intersections%transient_in_id               = buffer (12)
00145    msg_intersections%num_parts                     = buffer (13)
00146    msg_intersections%transient_out_id              = buffer (14)
00147    msg_intersections%num_vars                      = buffer (15)
00148    msg_intersections%requires_conserv_remap        = buffer (16)
00149    msg_intersections%relative_msg_tag              = buffer (17)
00150 
00151    npart = msg_intersections%num_parts
00152 
00153    ! In case we have a gridless grid npart is stored twice in buffer
00154    if (buffer(ip_msgint_inter+2*ndim_3d*npart+2*npart+1) == buffer (13)) then
00155       npart_alloc = 2 * npart
00156    else
00157       npart_alloc = npart
00158    endif
00159 
00160    if (npart > 0) then
00161 
00162       allocate (msg_intersections%intersections(npart_alloc))
00163 
00164       do n = 1, msg_intersections%num_parts
00165          msg_intersections%intersections(n)%intersection = &
00166             reshape (buffer(ip_msgint_inter+1+(n-1)*2*ndim_3d:ip_msgint_inter+n*2*ndim_3d), &
00167                      (/2,ndim_3d/))
00168       enddo
00169 
00170       msg_intersections%intersections(1:npart)%tgt_all_extents_grid_id = &
00171          buffer (ip_msgint_inter+2*ndim_3d*npart+1:ip_msgint_inter+2*ndim_3d*npart+npart)
00172 
00173       msg_intersections%intersections(1:npart)%src_all_extents_grid_id = &
00174          buffer (ip_msgint_inter+2*ndim_3d*npart+npart+1:ip_msgint_inter+2*ndim_3d*npart+2*npart)
00175 
00176       ! if we have a gridless grid, then there is additional grid information in buffer
00177       if (npart /= npart_alloc) then
00178 
00179          msg_intersections%intersections(npart+1:npart_alloc)%tgt_all_extents_grid_id = psmile_undef
00180          msg_intersections%intersections(npart+1:npart_alloc)%src_all_extents_grid_id = psmile_undef
00181 
00182          do n = 1, msg_intersections%num_parts
00183 
00184             msg_intersections%intersections(n+npart)%intersection =                       &
00185                reshape (buffer(ip_msgint_inter+2*ndim_3d*npart+2*npart+2+(n-1)*2*ndim_3d: &
00186                                ip_msgint_inter+2*ndim_3d*npart+2*npart+1+n*2*ndim_3d),    &
00187                         (/2,ndim_3d/))
00188          enddo
00189       endif
00190 
00191    else
00192 
00193       nullify (msg_intersections%intersections)
00194 
00195    endif
00196 
00197 end subroutine psmile_unpack_msg_intersections
00198 
00199 subroutine psmile_copy_msg_intersections (msg_intersections_to, &
00200                                           msg_intersections_from)
00201    use psmile_common, only : enddef_msg_intersections
00202 
00203    implicit none
00204 
00205    type (enddef_msg_intersections), intent (in)  :: msg_intersections_from
00206    type (enddef_msg_intersections), intent (out) :: msg_intersections_to
00207 
00208    msg_intersections_to = msg_intersections_from
00209 
00210    nullify (msg_intersections_to%intersections)
00211 
00212    allocate (msg_intersections_to%intersections (size (msg_intersections_from%intersections)))
00213 
00214    msg_intersections_to%intersections = msg_intersections_from%intersections
00215 
00216 end subroutine psmile_copy_msg_intersections

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1