//------------------------------------------------------------
// $Id: mpi2communication.h,v 1.2 2000/05/19 20:35:51 yamauchi Exp $
//------------------------------------------------------------
//	mpi2 communication
//	1996/7/10
//	Copyright (C) 1996--1998 YAMAUCHI Hitoshi 山内 斉
// 	通信関係 実装は MPI (commMpi2 関数群 でカプセル化)
//------------------------------------------------------------
#ifndef _mpi2communication_h
#define _mpi2communication_h 1

#include "req_handle_t.h"
#include "objectInfoInASpace.h"
#include "mpi2.h"

class Ray;
class intVerClass;
class SysInfoClass;
class ViewDataClass;
class SpaceParam;

//------------------------------------------------------------
// Init and end and barrier
//------------------------------------------------------------
extern void commMpi2_Init(int *pArgc, char ***pArgv);
extern void commMpi2_SizeAndRank(int *pSize, int *pRank);
extern void commMpi2_Finalize(void);
extern void commMpi2_Barrier(void);

//------------------------------------------------------------
// broadcast sysinfo
//------------------------------------------------------------
extern void commMpi2_BroadSysinfo(SysInfoClass    *pSys,
				  ViewDataClass   *pVw,
				  SpaceParam 	  *pSp);
extern void commMpi2_BroadObjInSpc(int bytesize, 
				   OBJINSPC_IMPLEMENT_TYPE *pDatOneDimArray);

// for PRC method
extern void commMpi2_BroadPRCSkipMap(int bytesize, 
				     OBJINSPC_IMPLEMENT_TYPE *pDatOneDimArray);

//------------------------------------------------------------
// send, recv object
//------------------------------------------------------------
class objBaseClass;
extern void commMpi2_sendObject(int dstRank, objBaseClass *pObj);
extern void commMpi2_recvObject(int srcRank, int dstRank, objBaseClass **ppObj);

//------------------------------------------------------------
// send, recv volume やがて object として統一すべきか?
//------------------------------------------------------------
class VolumeClass;
extern void commMpi2_sendVolume(int dstRank, VolumeClass *pObj);
extern void commMpi2_recvVolume(int srcRank, int dstRank, VolumeClass **ppObj);

//------------------------------------------------------------
// broad material
//------------------------------------------------------------
class materialClass;
extern void commMpi2_BroadMaterial(materialClass *pMat);

//------------------------------------------------------------
// recv probe 
// 	pSrcRank どこから受けられるか : 
//		NO が返った場合には、*pSrcRank は無意味である
//	recvStaff なにを受けるか(ray, intensity, object....)
//
// @param canRecv       	受けるものを指定する
// @param canRecvObject 	物体を受ける。どの物体を受けたかが返る
// @param pNumOfBytes   	受信物体のバイトサイズ
//------------------------------------------------------------
extern YorN commMpi2_canRecv(int *pSrcRank, 
			     enum communication_tags_e recvStaff,
			     int *pNumOfBytes);
			     
extern YorN commMpi2_canRecvObject(int *pSrcRank, int *pRecvTag);

//------------------------------------------------------------
// send, recv something complete? 
// (waiting completion of non blocking send, recv)
//------------------------------------------------------------
extern YorN commMpi2_isSendComplete(reqHandle_st req_handle);
extern YorN commMpi2_isRecvComplete(reqHandle_st req_handle);

//------------------------------------------------------------
// Isend, Irecv
//	non-blocking send, recv
//------------------------------------------------------------
#ifdef USE_MPI
#  include "mpi2communicationMPI.h"
#elif defined FOR_STANDALONE
#  include "mpi2communStandAlone.h"
#else
#  error "Error! : Set communication library (FOR_STANDALONE or USE_MPI)"
#endif

#endif				// #ifndef _mpi2communication_h
