2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) Scilab-Enterprises - 2016 - Cedric DELAMARRE
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 #ifndef __SCIMPICOMM_HXX__
14 #define __SCIMPICOMM_HXX__
16 // avoid c++ openmpi include
17 #define OMPI_SKIP_MPICXX
25 #include "dynlib_mpi.h"
28 class MPI_IMPEXP SciMpiComm : public types::UserType
32 SciMpiComm(int* piRanks, int iSize)
35 m_piWorldIndex = new int[m_iGroupSize];
36 memcpy(m_piWorldIndex, piRanks, m_iGroupSize * sizeof(int));
37 // create group from the world communicator
38 MPI_Group world_group;
39 MPI_Comm_group(MPI_COMM_WORLD, &world_group);
41 // create communicator from the group
42 MPI_Group_incl(world_group, m_iGroupSize, m_piWorldIndex, &m_group);
43 MPI_Comm_create(MPI_COMM_WORLD, m_group, &m_comm);
48 return new SciMpiComm(m_piWorldIndex, m_iGroupSize);
51 std::wstring getTypeStr() const
56 std::wstring getShortTypeStr() const
66 bool toString(std::wostringstream& ostr)
68 ostr << L"MPI communicator of size " << m_iGroupSize << std::endl;
69 ostr << L"World ranks:" << std::endl;
70 for (int i = 0; i < m_iGroupSize; i++)
72 ostr << " " << m_piWorldIndex[i];
85 delete[] m_piWorldIndex;
95 #endif //__SCIMPICOMM_HXX__