Jump to content
AntoineSfx

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

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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. 

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

both are in the points loop, but if the thing printed is exactly the same (and the calculation/memory needed is exactly the same) it will only do the print once, as VEX optimizes these things.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I would say its a feature :P...

whenever I use printf() without having a condition like: if(@ptnum == 0){printf("stuff");}
I kinda want to punch myself because of the millions of prints it wants to do..

  • Haha 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×