
void MPI_Sendrecv(double* sendbuf, int sendcount, int dest, int sendtag,
                  double* recvbuf, int recvcount, int source, int recvtag) {
  double tempSendBuffer[sendcount] ;
  double tempRecvBuffer[recvcount];
  int i;
  
  if (dest >= 0) for (i=0; i<sendcount; i++) tempSendBuffer[i]=sendbuf[i];
  if (source >= 0 && dest >= 0) {
    select
      when (true) {send(tempSendBuffer, dest, sendtag); recv(tempRecvBuffer, source, recvtag);}
      when (true) {recv(tempRecvBuffer, source, recvtag); send(tempSendBuffer, dest, sendtag);}
  }
  else {  /* either source or dest is invalid */
    if (source >= 0) recv(tempRecvBuffer, source, recvtag);
    if (dest >= 0) send(tempSendBuffer, dest, sendtag);
  }
  if (source >= 0) for (i=0; i<recvcount; i++) recvbuf[i]=tempRecvBuffer[i];
}

void main() {
  double x = 1.0*PID;
  double y;
  
  #pragma TASS assert NPROCS==2;
  MPI_Sendrecv(&x, 1, 1-PID, 0, &y, 1, 1-PID, 0);
  #pragma TASS assert y==1.0*(1-PID);
}