/****   Copyright (c) 2000, 2001  Alexandros V. Gerbessiotis
        Read copyright notice in file copy
 ****/
#undef  MPILIB
#define MPILIB
#define BSPLIB
#undef  BSPLIB


#ifdef BSPLIB
#include "bsp.h"
#define AIGET  bsp_get
#define AIHPGET  bsp_hpget
#define AIPUT  bsp_put
#define AIPT(A,B,C,D,E,F)  bsp_put(A,B,C,D,E)
#define AIHPPUT  bsp_hpput
#define AIHPPT(A,B,C,D,E,F)  bsp_put(A,B,C,D,E)
#define AISYNC bsp_sync
#define AISNC(Z) bsp_sync()
#define AIBARRIER bsp_sync
#define AIREALIZE bsp_sync
#define AIABORT bsp_abort
#define AIPID   bsp_pid
#define AINPROCS bsp_nprocs
#define AIREGISTER bsp_pushregister
#define AIREG(X,Y,Z) bsp_pushregister(X,Y)
#define AIDEREGISTER bsp_popregister
#define AITIME       bsp_time
#define AIBEGIN      bsp_begin
#define AIEND        bsp_end
#define AIL()    (bsp_l())
#define AIG()    (bsp_g())
#define AISETL(X) {}
#define AISETG(X) {}
#endif

#ifdef   MPILIB
#include <mpi.h>
extern MPI_Comm comm;
extern MPI_Win  win;
extern MPI_Win  win_max_ind;
extern MPI_Win  win_max_temp;
extern MPI_Win  win_column;
extern MPI_Win  win_row_tmp;
extern MPI_Win  win_row;
extern MPI_Win  win_collect_ind;
extern MPI_Win  win_collect_max;

#define AIBEGIN(X) (MPI_Init(&argc,&argv),mpi_basetime=MPI_Wtime())
#define AIPID() ((mpi_pid == -1)?(MPI_Comm_rank(MPI_COMM_WORLD,&mpi_pid),mpi_pid):mpi_pid) 
#define AINPROCS() ((mpi_nprocs== -1)?(MPI_Comm_size(MPI_COMM_WORLD,&mpi_nprocs),mpi_nprocs):mpi_nprocs)
#define AIBARRIER() MPI_Barrier(MPI_COMM_WORLD)
#define AIREGISTER(X,Y) MPI_Win_create((char *)(X),(Y),1,MPI_INFO_NULL ,MPI_COMM_WORLD,&win)
#define AIREG(X,Y,Z) MPI_Win_create((char *)(X),(Y),1,MPI_INFO_NULL\
        ,MPI_COMM_WORLD,&Z)
#define AIDEREGISTER(X) {}
#define AISYNC() MPI_Win_fence(0,win)
#define AISNC(Z) MPI_Win_fence(0,Z)
#define AIBARRIER() MPI_Barrier(MPI_COMM_WORLD)
#define AIPUT(X,Y,Z,W,R) MPI_Put((char *)(Y),(R),MPI_CHAR,(X),(W),(R),MPI_CHAR,win)
#define AIPT(X,Y,Z,W,R,S) MPI_Put((char *)(Y),(R),MPI_CHAR,(X),(W),(R),MPI_CHAR,S)
#define AIHPPUT(X,Y,Z,W,R) MPI_Put((char *)(Y),(R),MPI_CHAR,(X),(W),(R),MPI_CHAR,win)
#define AIHPPT(X,Y,Z,W,R,S) MPI_Put((char *)(Y),(R),MPI_CHAR,(X),(W),(R),MPI_CHAR,S)
#define AIGET(X,Y,W,Z,R) MPI_Get((char *)(Z),(R),MPI_CHAR,(X),(W),(R),MPI_CHAR,win)
#define AIHPGET(X,Y,W,Z,R) MPI_Get((char *)(Z),(R),MPI_CHAR,(X),(W),(R),MPI_CHAR,win)
#define AIEND() MPI_Barrier(MPI_COMM_WORLD),MPI_Finalize()
#define AIABORT(X) MPI_Abort(MPI_COMM_WORLD, __LINE__ )
#define AITIME() (MPI_Wtime()-mpi_basetime)
#define AIL()    (mpi_bsp_l)
#define AIG()    (mpi_bsp_g)
#define AISETL(X) (mpi_bsp_l=(X))
#define AISETG(X) (mpi_bsp_g=(X))
extern MPI_Comm comm;
extern MPI_Win  win;
extern int mpi_pid ;
extern int mpi_nprocs ;
extern double mpi_bsp_l ;
extern double mpi_bsp_g ;
extern double mpi_basetime;
#endif
