| 1 |
! (C) Copyright 2013 ECMWF. |
| 2 |
! |
| 3 |
! This software is licensed under the terms of the Apache Licence Version 2.0 |
| 4 |
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 5 |
! In applying this licence, ECMWF does not waive the privileges and immunities |
| 6 |
! granted to it by virtue of its status as an intergovernmental organisation nor |
| 7 |
! does it submit to any jurisdiction. |
| 8 |
|
| 9 |
#include "atlas/atlas_f.h" |
| 10 |
|
| 11 |
module atlas_Partitioner_module |
| 12 |
|
| 13 |
use fckit_owned_object_module, only: fckit_owned_object |
| 14 |
|
| 15 |
implicit none |
| 16 |
|
| 17 |
private :: fckit_owned_object |
| 18 |
|
| 19 |
public :: atlas_Partitioner |
| 20 |
public :: atlas_MatchingPartitioner |
| 21 |
public :: atlas_MatchingMeshPartitioner ! use MatchingPartitioner instead! |
| 22 |
|
| 23 |
private |
| 24 |
|
| 25 |
!----------------------------- |
| 26 |
! atlas_Partitioner ! |
| 27 |
!----------------------------- |
| 28 |
|
| 29 |
|
| 30 |
!------------------------------------------------------------------------------ |
| 31 |
TYPE, extends(fckit_owned_object) :: atlas_Partitioner |
| 32 |
|
| 33 |
! Purpose : |
| 34 |
! ------- |
| 35 |
! *Partitioner* : Object passed from atlas to inspect grid distribution |
| 36 |
|
| 37 |
! Methods : |
| 38 |
! ------- |
| 39 |
|
| 40 |
! Author : |
| 41 |
! ------ |
| 42 |
! 12-Mar-2014 Willem Deconinck *ECMWF* |
| 43 |
|
| 44 |
!------------------------------------------------------------------------------ |
| 45 |
contains |
| 46 |
procedure, public :: partition |
| 47 |
|
| 48 |
#if FCKIT_FINAL_NOT_INHERITING |
| 49 |
final :: atlas_Partitioner__final_auto |
| 50 |
#endif |
| 51 |
|
| 52 |
END TYPE atlas_Partitioner |
| 53 |
|
| 54 |
!------------------------------------------------------------------------------ |
| 55 |
|
| 56 |
interface atlas_Partitioner |
| 57 |
module procedure atlas_Partitioner__ctor |
| 58 |
module procedure atlas_Partitioner__ctor_type |
| 59 |
end interface |
| 60 |
|
| 61 |
interface atlas_MatchingPartitioner |
| 62 |
module procedure atlas_MatchingMeshPartitioner__ctor |
| 63 |
module procedure atlas_MatchingFunctionSpacePartitioner__ctor |
| 64 |
end interface |
| 65 |
|
| 66 |
interface atlas_MatchingMeshPartitioner |
| 67 |
module procedure atlas_MatchingMeshPartitioner__ctor |
| 68 |
end interface |
| 69 |
|
| 70 |
!======================================================== |
| 71 |
contains |
| 72 |
!======================================================== |
| 73 |
! ----------------------------------------------------------------------------- |
| 74 |
! Partitioner routines |
| 75 |
|
| 76 |
function atlas_Partitioner__ctor( config ) result(this) |
| 77 |
use atlas_config_module, only : atlas_Config |
| 78 |
use atlas_partitioner_c_binding |
| 79 |
type(atlas_Partitioner) :: this |
| 80 |
type(atlas_Config) :: config |
| 81 |
call this%reset_c_ptr( atlas__grid__Partitioner__new( config%CPTR_PGIBUG_B ) ) |
| 82 |
call this%return() |
| 83 |
end function |
| 84 |
|
| 85 |
function atlas_Partitioner__ctor_type( type ) result(this) |
| 86 |
use atlas_config_module, only : atlas_Config |
| 87 |
use atlas_partitioner_c_binding |
| 88 |
use fckit_C_interop_module, only : c_str |
| 89 |
type(atlas_Partitioner) :: this |
| 90 |
character(len=*), intent(in) :: type |
| 91 |
!-------------------------------------- |
| 92 |
call this%reset_c_ptr( atlas__grid__Partitioner__new_type( c_str(type) ) ) |
| 93 |
call this%return() |
| 94 |
end function |
| 95 |
|
| 96 |
function atlas_MatchingMeshPartitioner__ctor( mesh, config ) result(this) |
| 97 |
use atlas_mesh_module, only : atlas_Mesh |
| 98 |
use atlas_config_module, only : atlas_Config |
| 99 |
use atlas_partitioner_c_binding |
| 100 |
type(atlas_Partitioner) :: this |
| 101 |
type(atlas_Mesh) , intent(in) :: mesh |
| 102 |
type(atlas_Config), intent(in), optional :: config |
| 103 |
type(atlas_Config) :: opt_config |
| 104 |
if( present(config) ) then |
| 105 |
call this%reset_c_ptr( atlas__grid__MatchingMeshPartitioner__new( & |
| 106 |
mesh%CPTR_PGIBUG_A, config%CPTR_PGIBUG_B ) ) |
| 107 |
else |
| 108 |
opt_config = atlas_Config() |
| 109 |
call this%reset_c_ptr( atlas__grid__MatchingMeshPartitioner__new( & |
| 110 |
mesh%CPTR_PGIBUG_A, opt_config%CPTR_PGIBUG_B ) ) |
| 111 |
call opt_config%final() |
| 112 |
endif |
| 113 |
call this%return() |
| 114 |
end function |
| 115 |
|
| 116 |
|
| 117 |
function atlas_MatchingFunctionSpacePartitioner__ctor( functionspace, config ) result(this) |
| 118 |
use atlas_functionspace_module, only : atlas_FunctionSpace |
| 119 |
use atlas_config_module, only : atlas_Config |
| 120 |
use atlas_partitioner_c_binding |
| 121 |
type(atlas_Partitioner) :: this |
| 122 |
class(atlas_FunctionSpace) , intent(in) :: functionspace |
| 123 |
type(atlas_Config), intent(in), optional :: config |
| 124 |
type(atlas_Config) :: opt_config |
| 125 |
if( present(config) ) then |
| 126 |
call this%reset_c_ptr( atlas__grid__MatchingFunctionSpacePartitioner__new( & |
| 127 |
functionspace%CPTR_PGIBUG_A, config%CPTR_PGIBUG_B ) ) |
| 128 |
else |
| 129 |
opt_config = atlas_Config() |
| 130 |
call this%reset_c_ptr( atlas__grid__MatchingFunctionSpacePartitioner__new( & |
| 131 |
functionspace%CPTR_PGIBUG_A, opt_config%CPTR_PGIBUG_B ) ) |
| 132 |
call opt_config%final() |
| 133 |
endif |
| 134 |
call this%return() |
| 135 |
end function |
| 136 |
|
| 137 |
function partition(this,grid) result(distribution) |
| 138 |
use atlas_partitioner_c_binding |
| 139 |
use atlas_GridDistribution_module, only : atlas_GridDistribution |
| 140 |
use atlas_Grid_module, only : atlas_Grid |
| 141 |
type(atlas_GridDistribution) :: distribution |
| 142 |
class(atlas_Partitioner), intent(in) :: this |
| 143 |
class(atlas_Grid), intent(in) :: grid |
| 144 |
distribution = atlas_GridDistribution( atlas__grid__Partitioner__partition( this%CPTR_PGIBUG_A, grid%CPTR_PGIBUG_A ) ) |
| 145 |
call distribution%return() |
| 146 |
end function |
| 147 |
|
| 148 |
!------------------------------------------------------------------------------- |
| 149 |
|
| 150 |
#if FCKIT_FINAL_NOT_INHERITING |
| 151 |
ATLAS_FINAL subroutine atlas_Partitioner__final_auto(this) |
| 152 |
type(atlas_Partitioner), intent(inout) :: this |
| 153 |
#if FCKIT_FINAL_DEBUGGING |
| 154 |
write(0,*) "atlas_Partitioner__final_auto" |
| 155 |
#endif |
| 156 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 157 |
call this%final() |
| 158 |
#endif |
| 159 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 160 |
end subroutine |
| 161 |
#endif |
| 162 |
|
| 163 |
! ---------------------------------------------------------------------------------------- |
| 164 |
|
| 165 |
end module atlas_Partitioner_module |