Skip to content

Commit

Permalink
1) add a unit test for Fortran API redistribution; 2) fix compile bug…
Browse files Browse the repository at this point in the history
…s (tnx Willem)
  • Loading branch information
sbrdar committed Oct 31, 2023
1 parent 045f6b1 commit 6f5ed31
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 43 deletions.
19 changes: 14 additions & 5 deletions src/atlas/redistribution/detail/RedistributionInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,35 @@

#include <cstring>

#include "RedistributionImpl.h"
#include "RedistributionInterface.h"

//#include "atlas/functionspace/FunctionSpace.h"
#include "atlas/functionspace/detail/FunctionSpaceImpl.h"
#include "atlas/redistribution/detail/RedistributionImplFactory.h"

namespace atlas {
namespace redistribution {

// ----------------------------------------------------------------------------
// Fortran interfaces
// ----------------------------------------------------------------------------

extern "C" {

const Redistribution* atlas__Redistribution__new(
const functionspace::FunctionSpaceImpl* fspace1, const functionspace::FunctionSpaceImpl* fspace2) {
return new Redistribution(fspace1, fspace2);
detail::RedistributionImpl* atlas__Redistribution__new__config(
const functionspace::FunctionSpaceImpl* fspace1, const functionspace::FunctionSpaceImpl* fspace2,
const eckit::Configuration* config) {
ATLAS_ASSERT(config != nullptr);
std::string type;
config->get("type", type);
auto redist = redistribution::detail::RedistributionImplFactory::build(type);
redist->setup(fspace1, fspace2);
return redist;
}

}


// ----------------------------------------------------------------------------

} // namespace redistribution
} // namespace atlas
42 changes: 10 additions & 32 deletions src/atlas/redistribution/detail/RedistributionInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,31 @@
*/
#pragma once

//#include "atlas/functionspace/detail/FunctionSpaceImpl.h"
#include "atlas/redistribution/Redistribution.h"
namespace eckit {
class Configuration;
}

namespace atlas {
namespace functionspace{
class FunctionSpaceImpl;
}
namespace field {
class FieldSetImpl;
}
namespace grid {
class DistributionImpl;
}
} // namespace atlas

namespace atlas {
namespace grid {
namespace detail {
namespace grid {
class Grid;
} // namespace grid
} // namespace detail
} // namespace grid
using GridImpl = grid::detail::grid::Grid;
} // namespace atlas

namespace atlas {
namespace grid {
namespace redistribution {
namespace detail {
namespace partitioner {
class Partitioner;
} // namespace partitioner
} // namespace detail
} // namespace grid
using PartitionerImpl = grid::detail::partitioner::Partitioner;
} // namespace atlas


namespace atlas {
class RedistributionImpl;
}

// -------------------------------------------------------------------
// C wrapper interfaces to C++ routines
extern "C" {

const Redistribution* atlas__Redistribution__new(
const functionspace::FunctionSpaceImpl* fspace1, const functionspace::FunctionSpaceImpl* fspace2);
detail::RedistributionImpl* atlas__Redistribution__new__config(
const functionspace::FunctionSpaceImpl* fspace1, const functionspace::FunctionSpaceImpl* fspace2,
const eckit::Configuration* config);

}

} // namespace redistribution
} // namespace atlas
25 changes: 19 additions & 6 deletions src/atlas_f/redistribution/atlas_Redistribution_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
module atlas_Redistribution_module

use, intrinsic :: iso_c_binding, only : c_ptr
use atlas_config_module, only : atlas_Config
use atlas_functionspace_module, only : atlas_FunctionSpace
use fckit_owned_object_module, only: fckit_owned_object

Expand Down Expand Up @@ -49,8 +50,8 @@ module atlas_Redistribution_module
!------------------------------------------------------------------------------

interface atlas_Redistribution
module procedure atlas_Redistribution__cptr
module procedure atlas_Redistribution__ctor
module procedure ctor_cptr
module procedure ctor_create
end interface

private :: c_ptr
Expand All @@ -62,19 +63,31 @@ module atlas_Redistribution_module
! -----------------------------------------------------------------------------
! Redistribution routines

function atlas_Redistribution__cptr( cptr ) result(this)
function empty_config() result(config)
type(atlas_Config) :: config
config = atlas_Config()
call config%return()
end function

function ctor_cptr( cptr ) result(this)
use atlas_redistribution_c_binding
type(atlas_Redistribution) :: this
type(c_ptr), intent(in) :: cptr
call this%reset_c_ptr( cptr )
call this%return()
end function

function atlas_Redistribution__ctor( fspace1, fspace2 ) result(this)
function ctor_create( fspace1, fspace2, redist_name ) result(this)
use atlas_redistribution_c_binding
type(atlas_FunctionSpace), intent(in) :: fspace1, fspace2
class(atlas_FunctionSpace), intent(in) :: fspace1, fspace2
character(len=*), intent(in), optional :: redist_name
type(atlas_Redistribution) :: this
call this%reset_c_ptr( atlas__Redistribution__new(fspace1%CPTR_PGIBUG_A, fspace2%CPTR_PGIBUG_A) )
type(atlas_Config) :: config
config = empty_config()
call config%set("type", "RedistributeGeneric")
if (present(redist_name)) call config%set("type", redist_name)
call this%reset_c_ptr( atlas__Redistribution__new__config(fspace1%CPTR_PGIBUG_A, fspace2%CPTR_PGIBUG_A, config%CPTR_PGIBUG_B) )
call config%final()
call this%return()
end function

Expand Down
9 changes: 9 additions & 0 deletions src/tests/redistribution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

if( atlas_HAVE_ATLAS_FUNCTIONSPACE )

add_fctest( TARGET atlas_fctest_redistribution
MPI 4
CONDITION eckit_HAVE_MPI
LINKER_LANGUAGE Fortran
SOURCES fctest_redistribution.F90
LIBS atlas_f
ENVIRONMENT ${ATLAS_TEST_ENVIRONMENT}
)

ecbuild_add_test( TARGET atlas_test_redistribution_structured
SOURCES test_redistribution_structured.cc
MPI 8
Expand Down
67 changes: 67 additions & 0 deletions src/tests/redistribution/fctest_redistribution.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
! (C) Copyright 2013 ECMWF.
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
! In applying this licence, ECMWF does not waive the privileges and immunities
! granted to it by virtue of its status as an intergovernmental organisation nor
! does it submit to any jurisdiction.

! This File contains Unit Tests for testing the
! C++ / Fortran Interfaces to the State Datastructure
!
! @author Willem Deconinck
! @author Slavko Brdar

#include "fckit/fctest.h"

! -----------------------------------------------------------------------------

module fcta_Redistribution_fxt
use atlas_module
use, intrinsic :: iso_c_binding
implicit none
character(len=1024) :: msg
contains

end module

! -----------------------------------------------------------------------------

TESTSUITE_WITH_FIXTURE(fcta_Redistribution,fcta_Redistribution_fxt)

! -----------------------------------------------------------------------------

TESTSUITE_INIT
call atlas_library%initialise()
END_TESTSUITE_INIT

! -----------------------------------------------------------------------------

TESTSUITE_FINALIZE
call atlas_library%finalise()
END_TESTSUITE_FINALIZE

TEST( test_resitribution )
use atlas_module
use atlas_redistribution_module

implicit none
type(atlas_StructuredGrid) :: grid
type(atlas_functionspace_StructuredColumns) :: fspace1, fspace2
type(atlas_Redistribution) :: redist
type(c_ptr) :: cptr
grid = atlas_StructuredGrid("O16")
fspace1 = atlas_functionspace_StructuredColumns(grid, atlas_Partitioner("equal_regions"))
fspace2 = atlas_functionspace_StructuredColumns(grid, atlas_Partitioner("regular_bands"))

redist = atlas_Redistribution(fspace1, fspace2)

call redist%final()
call fspace2%final()
call fspace1%final()
call grid%final()
END_TEST

! -----------------------------------------------------------------------------

END_TESTSUITE

0 comments on commit 6f5ed31

Please sign in to comment.