Jump to content

Why does a part of this code runs only once in VEX ?


AntoineSfx

Recommended Posts

Input is a line, I'm trying to set a different pscale attribute on the first and last point. In PointWrangle (Run over Points), I have this:
 

f@pscale=chf("scl") ;
float scale=chf("scl");
printf("begin %f\n",scale);
printf("numpt=%d\n", @numpt);
printf("ptnum=%d\n", @ptnum);

if (@ptnum==0 || @ptnum== @numpt-1)
f@pscale=chf("scl") ;
else f@pscale=1 ;

 

output:

(twice the same thing)

begin 0.101000
numpt=10
ptnum=0
ptnum=1
ptnum=2
ptnum=3
ptnum=4
ptnum=5
ptnum=6
ptnum=7
ptnum=8
ptnum=9
begin 0.101000
numpt=10
ptnum=0
ptnum=1
ptnum=2
ptnum=3
ptnum=4
ptnum=5
ptnum=6
ptnum=7
ptnum=8
ptnum=9

 

Is the compiler parallelizing portion of codes which refer to points attributes ?

Edited by AntoineSfx
Link to comment
Share on other sites

54 minutes ago, Atom said:

I would construct the setup like this. In your IF statement it seems like you are "ORING zero with @ptnum. Use parenthesis to keep logic clear.

untitled-1.thumb.jpg.44a72189d9f87ea3d67ffe9239644e6d.jpg

Operators precedence is such that non contrived expressions don't require additional parenthesis.. Unless you want to assign the result of a comparison or something. It's built-in in the BNF.

However it doesn't explain why I have that behavior on the original code. 

Link to comment
Share on other sites

50 minutes ago, AntoineSfx said:

Operators precedence is such that non contrived expressions don't require additional parenthesis.. Unless you want to assign the result of a comparison or something. It's built-in in the BNF.

However it doesn't explain why I have that behavior on the original code. 

I found that if you drag the slider on your Scl param, it prints it twice.......but if you type in a number, press Enter...it does it ONCE as expected

(same as using the value ladder...prints it twice)

Edited by Noobini
Link to comment
Share on other sites

3 minutes ago, Noobini said:

I found that if you drag the slider on your Scl param, it prints it twice.......but if you type in a number, press Enter...it does it ONCE as expected

(same as using the value ladder...prints it twice)

the real question is, why does

printf("numpt=%d\n", @numpt);

seems to be outside of the points loop, while

printf("ptnum=%d\n", @ptnum);

seems to be be inside the points loop. I assume some optimization is made on the program, but I can't find exactly what. I know that vcc (or should I say the VM running its output) runs several threads, but it's unclear what happens to the VEX I wrote in that box.

Link to comment
Share on other sites

Point wrangle:

do a;
do b;
do c;
do a:
    on point 0
    on point 1
    on point 2

do b:
    on point 0
    on point 1
    on point 2

do c:
    on point 0
    on point 1
    on point 2

 

Detail wrangle point loop:

for (int i = 0; i < @numpt; i++)
{
    do a;
    do b;
    do c;
}
on point 0:
    do a
    do b
    do c

on point 1:
    do a
    do b
    do c

on point 2:
    do a
    do b
    do c

 

Since the scale and @numpt are uniform vars, print instruction was executed once and cached. @ptnum is varying and printf executed every time. It's an old issue with debugging VEX wrangles using printf().

Edited by f1480187
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...