source: CIVL/examples/concurrency/mpi-pthreads.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[28717d7]1/* CIVL model of simple hybrid MPI+threads program.
2 * The program has a defect.
[69bf2e6]3 * Commnad line execution:
4 * civl verify -min mpi-pthreads.cvl
[28717d7]5 */
[e6b02c8]6#include<comm.cvh>
[28717d7]7#define TAG 0
[c335e41]8#define NPROCS 2
9#define NTHREADS 2
[28717d7]10
[c335e41]11$gcomm gcomm = $gcomm_create($here, NPROCS);
[b70deeb]12
[c335e41]13void MPI_Process (int rank) {
14 $comm comm = $comm_create($here, gcomm, rank);
15 $proc threads[NTHREADS];
[c46e702]16
[28717d7]17 void Thread(int tid) {
[c335e41]18 int x = rank;
[4165892]19 $message in, out = $message_pack(rank, 1-rank, TAG, &x, sizeof(int));
[28717d7]20
21 for (int j=0; j<2; j++) {
[c335e41]22 if (rank == 1) {
23 for (int i=0; i<2; i++) $comm_enqueue(comm, out);
24 for (int i=0; i<2; i++) in = $comm_dequeue(comm, 1-rank, TAG);
[28717d7]25 } else {
[c335e41]26 for (int i=0; i<2; i++) in = $comm_dequeue(comm, 1-rank, TAG);
27 for (int i=0; i<2; i++) $comm_enqueue(comm, out);
[28717d7]28 }
29 }
30 }
[b70deeb]31
[c335e41]32 for (int i=0; i<NTHREADS; i++) threads[i] = $spawn Thread(i);
[5cccb8a]33 //for (int i=0; i<NTHREADS; i++) $wait(threads[i]);
34 $waitall(threads, NTHREADS);
[9cc2d02]35 $comm_destroy(comm);
[28717d7]36}
[b70deeb]37
38void main() {
[c335e41]39 $proc procs[NPROCS];
[c46e702]40
[c335e41]41 for (int i=0; i<NPROCS; i++) procs[i] = $spawn MPI_Process(i);
[5cccb8a]42 //for (int i=0; i<NPROCS; i++) $wait(procs[i]);
43 $waitall(procs, NPROCS);
[4f4cbcd]44 $gcomm_destroy(gcomm, NULL);
[b70deeb]45}
Note: See TracBrowser for help on using the repository browser.