magneto Posted March 20, 2012 Share Posted March 20, 2012 (edited) Basically I am wondering if it's possible to calculate accumulated values using VEX? Let's say a basic example of calculating the average or sum of all points. Something like: vector sum; sop vexop() { sum += P; } AFAIK VEX doesn't allow this kind of shared/static variables outside functions, right? How would one do something like this? Can you do it using a detail attribute? I couldn't find a way to access them in VEX. So I thought of doing this: sop vexop() { if (ptnum == 0) { vector sum; for (int i=0; i<Npt; i++) { vector p; import ( "P", p, 0, i ); sum += p; } } } Is this reasonable? Also how can I get this value out reliably? Right now I just print it. If I stored it in an attribute, the last point would have the correct value (if VEX loops points in order)? Thanks Edited March 20, 2012 by magneto 1 Quote Link to comment Share on other sites More sharing options...
symek Posted March 21, 2012 Share Posted March 21, 2012 Basically it won't work, unless you're in POPs, or inside SolverSOP. VEX virtual machine has a very specific architecture: 1) Copy attributes from geometry into Vex memory arrays. 2) Split array into chunks. 3) Run vex code in one thread per chunk, one time per point. 4) Copy all modified arrays back onto geometry. Accumulating values, recursion etc, are possible only outside VEX. As to attributes, you can access detail's in the same way as points' attributes. VEX will find it by name. 4 Quote Link to comment Share on other sites More sharing options...
magneto Posted March 21, 2012 Author Share Posted March 21, 2012 Thanks Symek. I understand it now. So you wouldn't use it even for 1 time accumulation-like calculations? By this I mean things like sum/average but only once, but not time/history dependent like solver SOP. I wanted to use VEX because Python version way very slow, so thought VEX might be much faster, and didn't want to dip into HDK yet Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted March 21, 2012 Share Posted March 21, 2012 (edited) ...and didn't want to dip into HDK yet Heh, well, HDK is not a one day trip for sure . But you can try InlineCPP. That's like one-two week trip to get to now each other a little. Edited March 21, 2012 by mantragora 1 Quote Link to comment Share on other sites More sharing options...
symek Posted March 21, 2012 Share Posted March 21, 2012 Heh, well, HDK is not a one day trip for sure . But you can try InlineCPP. That's like one-two week trip to get to now each other a little. +1 Not to mention, you can use VEX in Python also! 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted March 21, 2012 Author Share Posted March 21, 2012 Yeah I need to make some solid time before I cross the HDK waters @Symek, I knew I could call VEX in Python, but if I can't use VEX for this code, then it doesn't matter for me for this case. Inlinecpp looks like something I might try Quote Link to comment Share on other sites More sharing options...
tjeeds Posted March 21, 2012 Share Posted March 21, 2012 Sorry if I'm stating the obvious here but using Attribute Promote sum attributes to Detail class is pretty handily the speed and ease of use champion. If you can work that in as a precursor to whatever you're putting together you'll be well ahead of any other solution I can imagine. 2 Quote Link to comment Share on other sites More sharing options...
magneto Posted March 21, 2012 Author Share Posted March 21, 2012 Thanks for mentioning that trick. I know it but here I said sum/average for simplification. The actual calculation is way more complicated (500 lines) Quote Link to comment Share on other sites More sharing options...
edward Posted March 21, 2012 Share Posted March 21, 2012 Is this reasonable? Also how can I get this value out reliably? Right now I just print it. If I stored it in an attribute, the last point would have the correct value (if VEX loops points in order)? Offhand, the hack should work in theory to me. Have you tried some simple examples?Of course, it's not clear to me if this will be fast at all. Quote Link to comment Share on other sites More sharing options...
magneto Posted March 21, 2012 Author Share Posted March 21, 2012 Thanks Edward, I tried. It seems to work In fact it was pretty fast, still have to measure because I haven't finished it completely. But one thing I would appreciate if you can clear for me is if VEX loops through points in order? Like is it guaranteed for 0 to be executed before 1, and 1 before 2, etc? This is not relevant for my case because I use my own for loop, but still thought I would ask Quote Link to comment Share on other sites More sharing options...
edward Posted March 23, 2012 Share Posted March 23, 2012 No, points in VEX are not looped in order. If you think about it, there's no way for it to do that for multi-threading. Of course, you can always get lucky. The points are processed in "chunks" at a time so for a small number of points less than the "chunk" size, it won't be threaded and you may get it processed in ascending/descending order. 2 Quote Link to comment Share on other sites More sharing options...
magneto Posted March 23, 2012 Author Share Posted March 23, 2012 Thanks Eward, good info Would it be just like you said, if you set your VEX node to "No Threading"? I thought maybe that one might be handled differently. Quote Link to comment Share on other sites More sharing options...
anim Posted March 23, 2012 Share Posted March 23, 2012 VEX is based on SIMD architecture each instruction is run on all points before the next one so there is no way to access result value of any points to compute another, it simply doesn't exist yet, the only data you have access to are from input geometry and this is regardless of thread settings 2 Quote Link to comment Share on other sites More sharing options...
edward Posted March 23, 2012 Share Posted March 23, 2012 Would it be just like you said, if you set your VEX node to "No Threading"? I thought maybe that one might be handled differently. <shrugs> It may work today (or not) but expect the behaviour to change at any time. Basically, the order is *undefined*, so don't rely on it. 1 Quote Link to comment Share on other sites More sharing options...
magneto Posted March 23, 2012 Author Share Posted March 23, 2012 Thanks guys, appreciate the extra info Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.