aboutsummaryrefslogtreecommitdiff
path: root/src/Panda/message.h
blob: f76998f9409e8d9fdc2466d1253abd504e29f4f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef message_dot_h
#define message_dot_h

    
inline void send_message(void *buf, int count, MPI_Datatype data_type,
		int dest, int tag, MPI_Comm comm)
{
   MPI_Send(buf,count,data_type,dest,tag,comm);
#ifdef DEBUG
   printf("Sending message to %d of size %d with tag %d\n",
		dest, count, tag);
#endif
}

inline void nb_send_message(void *buf, int count, MPI_Datatype data_type,
		int dest, int tag, MPI_Comm comm, MPI_Request *request)
{
   MPI_Isend(buf,count,data_type,dest,tag,comm, request);
#ifdef DEBUG
   printf("Sending nonblocking message to %d of size %d with tag %d\n",
		 dest, count, tag);
#endif
}


inline void receive_message(void *buf, int count, MPI_Datatype datatype,
	int src, int tag, MPI_Comm comm, MPI_Status *status)
{
   MPI_Recv(buf,count,datatype, src,tag,comm,status);
#ifdef DEBUG
   printf("Received message from %d of size %d with tag %d\n",
		src, count, tag);
#endif
}


inline void nb_receive_message(void *buf, int count, MPI_Datatype datatype,
	int src, int tag, MPI_Comm comm, MPI_Request *request)
{
   MPI_Irecv(buf,count,datatype, src,tag,comm,request);
#ifdef DEBUG
   printf("Post a non-blocking receive for %d of size %d with tag %d\n",
		src, count, tag);
#endif
}


inline void mpi_test(MPI_Request *request, int *flag, MPI_Status *status)
{
  MPI_Test(request, flag, status);
}


inline void mpi_get_count(MPI_Status *status, MPI_Datatype datatype, int *len)
{
  MPI_Get_count(status, datatype, len);
}


inline void any_new_message(int *msg_code, int *msg_src,
			int *msg_tag,MPI_Status *msg_status)
{
  int flag;

  MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, msg_status);
  if (!flag){
    *msg_code = NO_MESSAGE;
    *msg_src = -1;
    *msg_tag = -1;
    return;
  }
  else{
    /* There some message waiting for us */
    *msg_tag = msg_status->MPI_TAG;
    *msg_src = msg_status->MPI_SOURCE;
    *msg_code = msg_status->MPI_TAG % 10;
    return;
  }
}

#endif