Hi -

Thanks for asking this question on chapel-users - others can
benefit from the question and answer. See below.


On 3/10/16, 9:05 AM, "Jyothi Krishna.V.S" <[email protected]> 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 ?

The problem is in the use of the sync variable.
See http://chapel.cray.com/docs/master/modules/internal/ChapelSyncvar.html

The issue is that when you initialized done$ with false, it became "full" -
i.e. this line creates a "full" sync variable with value "false":

   var done$: single bool = false;

Then, the statement

   done$

waits for the sync variable to become full, and leaves it empty (ignoring
the value). Since it was initialized, it started out full, and so
the statement always completes (without waiting).

I think your program would work as intended if you did not initialize done$
where you declare it. Here is a version that is perhaps closer to what

you intended:

proc test1(x: int ) {
     var x1: int = x;
     var done$: single bool; // done$ starts out empty

     if x == 1 then
        done$ = true; // waits for done$ to be empty, fills it

     begin with (ref x1){
       test2(x1);  // test1() may have exited by the time this is executed
       if(x1 == 2) {
         done$ = true; // waits for done$ to be empty, fills it
       }
     }
     done$; // waits for done$ to be full, empties it
 }
 proc test2(ref x1) {
     writeln(x1);
 }
 proc main(){
      test1(1); // --> CALL 1
      test1(2); // --> CALL2
 }



Cheers,


-michael


------------------------------------------------------------------------------
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