source: CIVL/examples/verifyThisProblems/ParallelGCD_2015_2.c@ c245979

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since c245979 was 260762f, checked in by Yihao Yan <yihaoyan1@…>, 10 years ago

verify this problems

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

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