source: CIVL/examples/verifyThisProblems/parallelGCD.c@ 0e12c94

1.23 2.0 main test-branch
Last change on this file since 0e12c94 was f7e5282, checked in by Yihao Yan <yihaoyan1@…>, 10 years ago

minor changes

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

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2author: Yihao
3
4Link(challenge 2): http://etaps2015.verifythis.org/challenges
5
6problem description:
7Various parallel GCD algorithms exist. In this challenge, we consider a
8simple Euclid-like algorithm with two parallel threads. One thread
9subtracts in one direction, the other thread subtracts in the other
10direction, and eventually this procedure converges on GCD.
11
12command: civl verify ParallelGCD_2015_2.c
13
14result: the problem is solved
15*/
16
17#include <civlc.cvh>
18#include <stdio.h>
19
20$input int A_BOUND=4;
21$input int B_BOUND=6;
22$input int A;
23$input int B;
24// assume the bound of A and B
25$assume (A>0 && B>0 && A<A_BOUND && B<B_BOUND);
26
27int myGCD(int a, int b) {
28 $proc proc_a;
29 $proc proc_b;
30
31 void worker1() {
32 while(a != b){
33 if(a>b){
34 int t1 = b;
35 int t2 = a-t1;
36 a = t2;
37 }
38 }
39 }
40 void worker2() {
41 while(a != b) {
42 if(b>a) {
43 int t1 = a;
44 int t2 = b-t1;
45 b = t2;
46 }
47 }
48 }
49 proc_a= $spawn worker1();
50 proc_b= $spawn worker2();
51 $wait(proc_a);
52 $wait(proc_b);
53 return a;
54}
55
56int seqGCD(int a, int b) {
57 while(a != b) {
58 if(a > b)
59 a = a-b;
60 if(b > a)
61 b = b-a;
62 }
63 return a;
64}
65
66void main() {
67 int result1 = myGCD(A, B);
68 int minAB = A < B ? A : B;
69
70 $assert($forall {i = (result1+1) .. (minAB)} (A%i != 0 || B%i != 0));
71 $assert(A%result1 == 0 && B%result1 == 0);
72}
Note: See TracBrowser for help on using the repository browser.