<commit_before>// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
//
// See http://www.salome-platform.org/ or email : <EMAIL>
//

#include "MPIAccess.hxx"
#include "InterpolationUtils.hxx"

#include <iostream>

using namespace std;

namespace ParaMEDMEM
{
  /*! \defgroup mpi_access MPIAccess
    Class \a MPIAccess is the gateway to the MPI library.
    It is a helper class that gathers the calls to the MPI
    library that are made in the ParaMEDMEM library. This gathering
    allows easier gathering of information about the communication
    in the library. With MPIAccess, tags are managed automatically
    and asynchronous operations are easier.

    It is typically called after the MPI_Init() call in a program. It is afterwards passed as a parameter to the constructors of ParaMEDMEM objects so that they access the MPI library via the MPIAccess.

    As an example, the following code initializes a processor group made of the zero processor.

    \verbatim
    #include "MPIAccess.hxx"
    #include "ProcessorGroup.hxx"

    int main(int argc, char** argv)
    {
    //initialization
    MPI_Init(&argc, &argv);
    ParaMEDMEM::CommInterface comm_interface;

    //setting up a processor group with proc 0
    set<int> procs;
    procs.insert(0);
    ParaMEDMEM::ProcessorGroup group(procs, comm_interface);

    ParaMEDMEM::MPIAccess mpi_access(group);

    //cleanup
    MPI_Finalize();
    }
    \endverbatim
  */


  /*! Creates a MPIAccess that is based on the processors included in \a ProcessorGroup.
    This class may be called for easier use of MPI API.

    \param ProcessorGroup MPIProcessorGroup object giving access to group management
    \param BaseTag and MaxTag define the range of tags to be used.
    Tags are managed by MPIAccess. They are cyclically incremented.
    When there is a Send or a Receive operation there is a new RequestId tag returned
    to the caller. That RequestId may be used to manage the operation Wait, Check of
    status etc... The MPITag internally managed by MPIAccess is used as "tag" argument
    in MPI call.
  */

  MPIAccess::MPIAccess(MPIProcessorGroup * ProcessorGroup, int BaseTag, int MaxTag) :
    _comm_interface( ProcessorGroup->getCommInterface() ) ,
    _intra_communicator( ProcessorGroup->getComm() )
  {
    int mpitagub ;
    int flag ;
    //MPI_Attr_get does not run with _IntraCommunicator ???
    //MPI_Attr_get(*_IntraCommunicator,MPI_TAG_UB,&mpitagub,&flag) ;
    MPI_Attr_get(MPI_COMM_WORLD,MPI_TAG_UB,&mpitagub,&flag) ;
    mpitagub=abs(mpitagub);
    if ( BaseTag != 0 )
      BaseTag = (BaseTag/MODULO_TAG)*MODULO_TAG ;
    if ( MaxTag == 0 )
      MaxTag = (mpitagub/MODULO_TAG-1)*MODULO_TAG ;
    MPI_Comm_rank( *_intra_communicator, &_my_rank ) ;
    if ( !flag | (BaseTag < 0) | (BaseTag >= MaxTag) | (MaxTag > mpitagub) )
      throw INTERP_KERNEL::Exception("wrong call to MPIAccess constructor");

    _processor_group = ProcessorGroup ;
    _processor_group_size = _processor_group->size() ;
    _trace = false ;

    _base_request = -1 ;
    _max_request = std::numeric_limits<int>::max() ;
    _request = _base_request ;
    
    _base_MPI_tag = BaseTag ;
    _max_MPI_tag = MaxTag ;
    
    _send_request = new int[ _processor_group_size ] ;
    _recv_request = new int[ _processor_group_size ] ;
<commit_msg>Debug vbd to correct the invalid use of parameter.<commit_after>// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
//
// See http://www.salome-platform.org/ or email : <EMAIL>
//

#include "MPIAccess.hxx"
#include "InterpolationUtils.hxx"

#include <iostream>

using namespace std;

namespace ParaMEDMEM
{
  /*! \defgroup mpi_access MPIAccess
    Class \a MPIAccess is the gateway to the MPI library.
    It is a helper class that gathers the calls to the MPI
    library that are made in the ParaMEDMEM library. This gathering
    allows easier gathering of information about the communication
    in the library. With MPIAccess, tags are managed automatically
    and asynchronous operations are easier.

    It is typically called after the MPI_Init() call in a program. It is afterwards passed as a parameter to the constructors of ParaMEDMEM objects so that they access the MPI library via the MPIAccess.

    As an example, the following code initializes a processor group made of the zero processor.

    \verbatim
    #include "MPIAccess.hxx"
    #include "ProcessorGroup.hxx"

    int main(int argc, char** argv)
    {
    //initialization
    MPI_Init(&argc, &argv);
    ParaMEDMEM::CommInterface comm_interface;

    //setting up a processor group with proc 0
    set<int> procs;
    procs.insert(0);
    ParaMEDMEM::ProcessorGroup group(procs, comm_interface);

    ParaMEDMEM::MPIAccess mpi_access(group);

    //cleanup
    MPI_Finalize();
    }
    \endverbatim
  */


  /*! Creates a MPIAccess that is based on the processors included in \a ProcessorGroup.
    This class may be called for easier use of MPI API.

    \param ProcessorGroup MPIProcessorGroup object giving access to group management
    \param BaseTag and MaxTag define the range of tags to be used.
    Tags are managed by MPIAccess. They are cyclically incremented.
    When there is a Send or a Receive operation there is a new RequestId tag returned
    to the caller. That RequestId may be used to manage the operation Wait, Check of
    status etc... The MPITag internally managed by MPIAccess is used as "tag" argument
    in MPI call.
  */

  MPIAccess::MPIAccess(MPIProcessorGroup * ProcessorGroup, int BaseTag, int MaxTag) :
    _comm_interface( ProcessorGroup->getCommInterface() ) ,
    _intra_communicator( ProcessorGroup->getComm() )
  {
    void *v ;
    int mpitagub ;
    int flag ;
    //MPI_Comm_get_attr does not run with _IntraCommunicator ???
    //MPI_Comm_get_attr(*_IntraCommunicator,MPID_TAG_UB,&mpitagub,&flag) ;
    MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_TAG_UB,&v,&flag) ;
    mpitagub=*(reinterpret_cast<int*>(v));
    if ( BaseTag != 0 )
      BaseTag = (BaseTag/MODULO_TAG)*MODULO_TAG ;
    if ( MaxTag == 0 )
      MaxTag = (mpitagub/MODULO_TAG-1)*MODULO_TAG ;
    MPI_Comm_rank( *_intra_communicator, &_my_rank ) ;
    if ( !flag | (BaseTag < 0) | (BaseTag >= MaxTag) | (MaxTag > mpitagub) )
      throw INTERP_KERNEL::Exception("wrong call to MPIAccess constructor");

    _processor_group = ProcessorGroup ;
    _processor_group_size = _processor_group->size() ;
    _trace = false ;

    _base_request = -1 ;
    _max_request = std::numeric_limits<int>::max() ;
    _request = _base_request ;
    
    _base_MPI_tag = BaseTag ;
    _max_MPI_tag = MaxTag ;
    
    _send_request = new int[ _processor_group_size ] ;
    _recv_request = new int[ _processor_group_size ] ;

{'fraction_non_alphanumeric': 0.07951032521330531, 'fraction_numerical': 0.007666625448250278, 'mean_word_length': 3.422088572990705, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1181291', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2393, 'n_words': 904}