Normal Vex Behavior

   2305   5   0
User Avatar
Member
113 posts
Joined: 7月 2005
Offline
I think I may be going crazy. If not, could someone please explain what I'm doing wrong, (Or at least thinking wrong )?

I start with a simple grid sop(3 x 3, rows & columns).
I feed this into a pointWrangle SOP.
The Vex code is Simple(I'm trying to identify the leftmost points):
printf("pt:%d\n", @ptnum);
if(@ptnum % 3)
    printf("pt:%d ->copy\n",@ptnum);
else
    printf("pt:%d ->src\n",@ptnum);

The output then prints:
pt:0
pt:1
pt:2
pt:3
pt:4
pt:5
pt:6
pt:7
pt:8
pt:0 ->src
pt:3 ->src
pt:6 ->src
pt:1 ->copy
pt:2 ->copy
pt:4 ->copy
pt:5 ->copy
pt:7 ->copy
pt:8 ->copy


I might be missing something, but isn't the sequence supposed to flow linearly, from the first point to the last?
According to this output, the node seems to be making three passes, one for each print statement.

Is this expected behavior or am I going nuts?
Thanks for any help.

Image Not Found
Edited by rudeypunk - 2020年7月21日 09:53:29

Attachments:
stumper.hip (84.1 KB)

User Avatar
Member
52 posts
Joined: 6月 2016
Offline
//printf("pt:%d\n", @ptnum);
if(@ptnum % 3 == 0)
{
    printf("pt:%d ->copy\n",@ptnum);
} else {
    printf("pt:%d ->src\n",@ptnum);
}

your first line is executed one time on every points, then I think your code is not properly written, try this code with brackets
User Avatar
Member
113 posts
Joined: 7月 2005
Offline
Thanks c0Y!

Regretfully I get the same results.
I tried to reproduce your code:

printf("pt:%d\n", @ptnum);
if(@ptnum % 3)
{
    printf("pt:%d ->copy\n",@ptnum);
}else{
    printf("pt:%d ->src\n",@ptnum);
}

Cheers
User Avatar
Member
8043 posts
Joined: 9月 2011
Offline
rudeypunk
Is this expected behavior or am I going nuts?

Yes that is expected. VEX doesn't run in simple loop over the points. It splits the code up into parts that can run the fewest number of times. For example, if you have ‘print foo’ in the code it will only print once, not once per point. There is also no guarantee of the order in which the code runs, as it is meant to run in parallel for large numbers of elements.
User Avatar
Member
113 posts
Joined: 7月 2005
Offline
Thank you jsmack!

If I had not heard it from a Side FX person, I would not have believed it
Actually is does make sense when viewed from a parallel perspective.

Cheers
User Avatar
Member
16 posts
Joined: 10月 2018
Offline
for linear sequence just use
Run over: Detail (only once) + loop

int totalPoints = npoints(0);
printf("--- Loop start\n");
for (int i = 0; i < totalPoints; i++)
{
    printf("pt:%d\n", i);
    if(i % 3)
        printf("pt:%d ->copy\n",i);
    else
        printf("pt:%d ->src\n",i);
}
printf("--- Loop end\n\n");

output:
— Loop start
pt:0
pt:0 ->src
pt:1
pt:1 ->copy
pt:2
pt:2 ->copy
pt:3
pt:3 ->src
pt:4
pt:4 ->copy
pt:5
pt:5 ->copy
pt:6
pt:6 ->src
pt:7
pt:7 ->copy
pt:8
pt:8 ->copy
— Loop end
Edited by DmitriiP - 2020年7月21日 22:11:19
  • Quick Links