source: CIVL/examples/concurrency/hybrid.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.1 KB
RevLine 
[b70deeb]1/* CIVL model of simple hybrid MPI+threads program.
2 * The program has a defect.
3 */
[e6b02c8]4#include<comm.cvh>
[b70deeb]5#include<stdio.h>
6#include "mp_root2.cvh"
7#define TAG 0
8
9void MPI_Process (int __rank) {
10#include "mp_proc2.cvh"
11 int rank;
[c46e702]12 _Bool tStart = $false;
[c905758]13 MPI_Comm MPI_COMM_WORLD = $comm_create($here, __MPI_Comm_World, __rank);
[c46e702]14
[b70deeb]15 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
16 $proc threads[2];
17 void Thread(int tid) {
18 int x = 2*rank + tid, y;
19
[c46e702]20 $when(tStart);
[b70deeb]21 for (int j=0; j<2; j++) {
[607ad68]22 if (rank == 1) {
[b70deeb]23 for (int i=0; i<2; i++)
[607ad68]24 MPI_Send(&x, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD);
[b70deeb]25 for (int i=0; i<2; i++)
26 MPI_Recv(&y, 1, MPI_INT, 0, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
[607ad68]27 } else if (rank == 0) {
[b70deeb]28 for (int i=0; i<2; i++)
[607ad68]29 MPI_Recv(&y, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
30 for (int i=0; i<2; i++)
31 MPI_Send(&x, 1, MPI_INT, 1, TAG, MPI_COMM_WORLD);
[b70deeb]32 }
33 }
34 }
[c46e702]35 for (int i=0; i<2; i++) {
36 threads[i] = $spawn Thread(i);
[b70deeb]37 }
[c46e702]38 tStart = $true;
[c905758]39 for (int i=0; i<2; i++) $wait(threads[i]);
[48bfab9]40 $comm_destroy(MPI_COMM_WORLD);
[b70deeb]41}
Note: See TracBrowser for help on using the repository browser.