Skip to content

Commit

Permalink
add Fortran API for redistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrdar committed Oct 31, 2023
1 parent 5ce3000 commit 045f6b1
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/atlas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ linalg/dense/MatrixMultiply_EckitLinalg.cc
list (APPEND atlas_redistribution_srcs
redistribution/Redistribution.h
redistribution/Redistribution.cc
redistribution/detail/RedistributionInterface.h
redistribution/detail/RedistributionInterface.cc
redistribution/detail/RedistributionImpl.h
redistribution/detail/RedistributionImpl.cc
redistribution/detail/RedistributionImplFactory.h
Expand Down
35 changes: 35 additions & 0 deletions src/atlas/redistribution/detail/RedistributionInterface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* (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.
*/

#include <cstring>

#include "RedistributionInterface.h"

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

namespace atlas {

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

extern "C" {

const Redistribution* atlas__Redistribution__new(
const functionspace::FunctionSpaceImpl* fspace1, const functionspace::FunctionSpaceImpl* fspace2) {
return new Redistribution(fspace1, fspace2);
}
}


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

} // namespace atlas
61 changes: 61 additions & 0 deletions src/atlas/redistribution/detail/RedistributionInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* (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.
*/
#pragma once

//#include "atlas/functionspace/detail/FunctionSpaceImpl.h"
#include "atlas/redistribution/Redistribution.h"

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 detail {
namespace partitioner {
class Partitioner;
} // namespace partitioner
} // namespace detail
} // namespace grid
using PartitionerImpl = grid::detail::partitioner::Partitioner;
} // namespace atlas


namespace atlas {

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

const Redistribution* atlas__Redistribution__new(
const functionspace::FunctionSpaceImpl* fspace1, const functionspace::FunctionSpaceImpl* fspace2);

}

} // namespace atlas
4 changes: 4 additions & 0 deletions src/atlas_f/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/functionspace/EdgeColumns.h
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/functionspace/detail/PointCloudInterface.h
MODULE atlas_functionspace_PointCloud_c_binding
OUTPUT functionspace_PointCloud_c_binding.f90)
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/redistribution/detail/RedistributionInterface.h
MODULE atlas_redistribution_c_binding
OUTPUT redistribution_c_binding.f90)

if( atlas_HAVE_ATLAS_NUMERICS )
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/numerics/Nabla.h)
Expand Down Expand Up @@ -233,6 +236,7 @@ ecbuild_add_library( TARGET atlas_f
parallel/atlas_Checksum_module.fypp
parallel/atlas_HaloExchange_module.fypp
projection/atlas_Projection_module.F90
redistribution/atlas_Redistribution_module.F90
internals/atlas_read_file.h
internals/atlas_read_file.cc
internals/Library.h
Expand Down
98 changes: 98 additions & 0 deletions src/atlas_f/redistribution/atlas_Redistribution_module.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
! (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.

#include "atlas/atlas_f.h"

module atlas_Redistribution_module

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

implicit none

public :: atlas_Redistribution

private

!-----------------------------
! atlas_Redistribution !
!-----------------------------


!------------------------------------------------------------------------------
TYPE, extends(fckit_owned_object) :: atlas_Redistribution

! Purpose :
! -------
! *Redistribution* : Object passed from atlas to inspect redistribution

! Methods :
! -------

! Author :
! ------

!------------------------------------------------------------------------------
contains

#if FCKIT_FINAL_NOT_INHERITING
final :: atlas_Redistribution__final_auto
#endif
END TYPE atlas_Redistribution

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

interface atlas_Redistribution
module procedure atlas_Redistribution__cptr
module procedure atlas_Redistribution__ctor
end interface

private :: c_ptr
private :: fckit_owned_object

!========================================================
contains
!========================================================
! -----------------------------------------------------------------------------
! Redistribution routines

function atlas_Redistribution__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)
use atlas_redistribution_c_binding
type(atlas_FunctionSpace), intent(in) :: fspace1, fspace2
type(atlas_Redistribution) :: this
call this%reset_c_ptr( atlas__Redistribution__new(fspace1%CPTR_PGIBUG_A, fspace2%CPTR_PGIBUG_A) )
call this%return()
end function

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

#if FCKIT_FINAL_NOT_INHERITING
ATLAS_FINAL subroutine atlas_Redistribution__final_auto(this)
type(atlas_Redistribution), intent(inout) :: this
#if FCKIT_FINAL_DEBUGGING
write(0,*) "atlas_Redistribution__final_auto"
#endif
#if FCKIT_FINAL_NOT_PROPAGATING
call this%final()
#endif
FCKIT_SUPPRESS_UNUSED( this )
end subroutine
#endif

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

end module atlas_Redistribution_module

0 comments on commit 045f6b1

Please sign in to comment.