//------------------------------------------------------------
// $Id: mpi2communicationMPI.h,v 1.1.1.1 1999/11/25 06:26:11 yamauchi Exp $
//------------------------------------------------------------
// mpi2communication for MPI version
//	Copyright 1999 (C) YAMAUCHI Hitoshi 
// template 化した Isend と Irecv の MPI 版
//------------------------------------------------------------
#ifndef _mpi2communicationMPI_h
#define _mpi2communicationMPI_h
#ifndef USE_MPI
#  error "Error! : This file is for MPI Mode! Check compile option."
#endif

#include <assert.h>
#include "mpi2.h"
#include "req_handle_t.h"

//------------------------------------------------------------
// Isend, Irecv 
//    send, wait ともに wait しないので必ず受信をチェックする
//------------------------------------------------------------
template < class T >
static inline 
reqHandle_st commMpi2_IsendObj(int destRank, T *pObj, int numOfObj)
{
    assert(destRank >= 0);
    assert(pObj != NULL);
    assert(numOfObj > 0);
    MPI_Request  requestID;
    reqHandle_st req_handle;

    MPI_Isend(pObj, (sizeof( T ) * numOfObj), MPI_BYTE, destRank,
	      T::getTAG(), MPI_COMM_WORLD, &requestID);
    req_handle.req = requestID;

    // MPI_Wait をしないでそのまま返る 必ず送信完了のテストが必要
    return(req_handle);
}

template < class T > 
static inline 
reqHandle_st commMpi2_IrecvObj(int srcRank, T *pObj, int numOfObj)
{
    assert(srcRank >= 0);
    assert(pObj != NULL);
    assert(numOfObj > 0);

    MPI_Request  requestID;
    reqHandle_st req_handle;

    MPI_Irecv(pObj, (sizeof( T ) * numOfObj), MPI_BYTE, srcRank,
 	      T::getTAG(), MPI_COMM_WORLD, &requestID);
    req_handle.req = requestID;
     
    // MPI_Wait をしないでそのまま返る 必ず受信完了のテストが必要
    return(req_handle);
}

#endif				// #ifdef _mpi2communicationMPI_h
