source: CIVL/examples/concurrency/mp_proc2.cvh@ b5f707b

1.23 2.0 main test-branch
Last change on this file since b5f707b was 3ff27cf, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

updated examples since $assert/$assume has been changed to functions; fixed the model builder for the new side-effect remover.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2085 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include <civlc.cvh>
2
3int MPI_Comm_size(MPI_Comm comm, int *size) {
4 *size = $comm_size(comm);
5 return 0;
6}
7
8int MPI_Comm_rank(MPI_Comm comm, int* rank) {
9 // this only works for MPI_COMM_WORLD.
10 // for multiple communicators, you will need
11 // a map (array) from PID to rank for each comm
12 *rank = $comm_place(comm);
13 return 0;
14}
15
16int MPI_Send(void *buf, int count, MPI_Datatype datatype,
17 int dest, int tag, MPI_Comm comm) {
18 //$atom {
19 int size;
20
21 switch (datatype) {
22 case MPI_INT:
23 buf = (int*)buf;
24 size = count*sizeof(int);
25 break;
26 case MPI_FLOAT:
27 buf = (float*)buf;
28 size = count*sizeof(float);
29 break;
30 case MPI_DOUBLE:
31 buf = (double*)buf;
32 size = count*sizeof(double);
33 break;
34 case MPI_CHAR:
35 buf = (char*)buf;
36 size = count*sizeof(char);
37 break;
38 default:
39 printf("Unsupported datatype %d\n", datatype);
40 $assert(($false));
41 }
42 $message out = $message_pack(__rank, dest, tag, buf, size);
43 $comm_enqueue(comm, out);
44 //}
45 return 0;
46}
47
48int MPI_Recv(void *buf, int count, MPI_Datatype datatype,
49 int source, int tag, MPI_Comm comm, MPI_Status *status) {
50 $message in = $comm_dequeue(comm, source, tag);
51 //$atom {
52 int size;
53
54 switch (datatype) {
55 case MPI_INT:
56 buf = (int*)buf;
57 size = count*sizeof(int);
58 break;
59 case MPI_FLOAT:
60 buf = (float*)buf;
61 size = count*sizeof(float);
62 break;
63 case MPI_DOUBLE:
64 buf = (double*)buf;
65 size = count*sizeof(double);
66 break;
67 case MPI_CHAR:
68 buf = (char*)buf;
69 size = count*sizeof(char);
70 break;
71 default:
72 printf("Unsupported datatype %d\n", datatype);
73 $assert(($false));
74 }
75 $message_unpack(in, buf, size);
76 if (status != MPI_STATUS_IGNORE) {
77 status->MPI_SOURCE = in.source;
78 status->MPI_TAG = in.tag;
79 status->size = in.size;
80 }
81 //}
82 return 0;
83}
84
85$when (__start);
Note: See TracBrowser for help on using the repository browser.