CommCwipi.cpp 2.85 KB
Newer Older
1 2
///////////////////////////////////////////////////////////////////////////////
//
Kilian Lackhove's avatar
Kilian Lackhove committed
3
// File CommCwipi.cpp
4 5 6 7 8
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
9
// Copyright (c) 2018 Kilian Lackhove
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: MPI communication implementation
//
///////////////////////////////////////////////////////////////////////////////

#include <LibUtilities/BasicUtils/SharedArray.hpp>
38
#include <LibUtilities/Communication/CommCwipi.h>
39

Kilian Lackhove's avatar
Kilian Lackhove committed
40
#include <cwipi.h>
41 42 43 44 45 46

namespace Nektar
{
namespace LibUtilities
{

47 48
std::string CommCwipi::className = GetCommFactory().RegisterCreatorFunction(
    "CWIPI", CommCwipi::create, "Parallel communication using MPI with CWIPI.");
49 50 51 52

/**
 *
 */
53
CommCwipi::CommCwipi(int narg, char *arg[]) : CommMpi()
54
{
Kilian Lackhove's avatar
Kilian Lackhove committed
55 56 57
    int init = 0;
    MPI_Initialized(&init);
    ASSERTL0(!init, "MPI has already been initialised.");
58

Kilian Lackhove's avatar
Kilian Lackhove committed
59 60 61 62 63
    int retval = MPI_Init(&narg, &arg);
    if (retval != MPI_SUCCESS)
    {
        ASSERTL0(false, "Failed to initialise MPI");
    }
64

65
    std::string localName = "";
66 67
    for (int i = 0; i < narg; ++i)
    {
68 69
        if (!std::strcmp(arg[i], "--cwipi"))
        {
70
            localName = arg[i + 1];
71 72 73
        }
    }

Kilian Lackhove's avatar
Kilian Lackhove committed
74
    MPI_Comm localComm;
75
    cwipi_init(MPI_COMM_WORLD, localName.c_str(), &localComm);
Kilian Lackhove's avatar
Kilian Lackhove committed
76
    m_comm = localComm;
77

78 79
    MPI_Comm_size(m_comm, &m_size);
    MPI_Comm_rank(m_comm, &m_rank);
80

Kilian Lackhove's avatar
Kilian Lackhove committed
81
    m_type = "Parallel MPI with CWIPI";
82 83 84 85 86
}

/**
 *
 */
Kilian Lackhove's avatar
Kilian Lackhove committed
87
CommCwipi::~CommCwipi()
88 89 90 91 92 93
{
}

/**
 *
 */
Kilian Lackhove's avatar
Kilian Lackhove committed
94
void CommCwipi::v_Finalise()
95
{
Kilian Lackhove's avatar
Kilian Lackhove committed
96
    cwipi_finalize();
97
    CommMpi::v_Finalise();
98 99 100
}
}
}