Hello --

I believe the surprising result here arises out of confusion between
true and false values in bool variables and full and empty states for
sync and single variables, and perhaps also between how sync and single
variables differ.  The declaration

   var done$: single bool = false;

sets done$ to the value false, but also makes its state "full".  The
implicit test against the empty state at the end of test1() therefore
always succeeds and the test1(1) call completes.  Thus the parallel call
to test2() in test1(1) may occur after test1() has returned and the ref
to x1 is no longer valid.

The call to test1(2) behaves similarly but has an additional problem.
It can print a corrupted value for x1 for the same reason as test1(1)
does.  Because done$ is a single var it has implicit ref intent in the
body of the begin-stmt.  In addition, because done$ is a single var, not
a sync, it is only legal to fill it once.  So one of two things can
happen with the assignment marked 'SYNC LINE', depending on whether the
begin-stmt body task is executed before test1(2) completes or not.  If
test1(2) has not returned when the 'SYNC LINE' executes then an error
message and halt will occur due to the attempted second assignment to
the single var done$, because single vars can only be assigned once.
But if test1(2) has already returned then the reference to done$ in the
begin-stmt body will be corrupt in the same way the reference to x1 is,
and results are unpredictable.

If you just remove the initialization from the declaration of done$ then
the program will hang in the test1(1) call, because the done$ reference
at the end of test1() will never find the variable full.  In this case
the test1(2) call will never execute.  If you also remove the x1==2 test
on the 'SYNC LINE' assignment then the program runs to completion and
produces the expected output:

  1
  2

Finally, if you restore the initialization of done$ and add a some logic
to prevent test1() from returning before the begin-stmt completes you
can force the program to do the 'SYNC LINE' assignment, and then you
will see the error message and halt I described about.

Hope this helps!

greg


On Thu, 10 Mar 2016, Jyothi Krishna.V.S wrote:

Hi,
In the below program
proc test1(x: int ) {
   var x1: int = x;
   var done$: single bool = false;
   begin with (ref x1){
      test2(x1);
      if(x1 == 2) then
            done$ = true; // ---> SYNC LINE
     } done$; }
proc test2(ref x1) {
      writeln(x1); }
proc main(){
    test1(1); // --> CALL 1
    test1(2); // --> CALL2 }
I am getting values currupted for both the function calls CALL1 and CALL2.
I understand why we get currupted value for CALL 1(since the SYNC LINE is
not executed). but why call 2 ?

--
Jyothi Krishna V.S.


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to