Aearon Posted November 6, 2008 Share Posted November 6, 2008 (edited) is there anyway to cast an integer to string in vex? i'm trying to do an equivalent of the partition sop in vex using something like: string grpname = "grp" + (string) ptnum; addgroup(grpname,ptnum) (this is just a simple example that would create a group per point named grp$PT in expression speak) is this possible? casting to string like that doesn't seem to work. Edited November 6, 2008 by Aearon Quote Link to comment Share on other sites More sharing options...
rdg Posted November 6, 2008 Share Posted November 6, 2008 is there anyway to cast an integer to string in vex? take a look at the sprintf function: string mystring = sprintf("grp%d", pnum); it should do what you want. Looking forward to see what you're up to ... Quote Link to comment Share on other sites More sharing options...
eetu Posted November 6, 2008 Share Posted November 6, 2008 (edited) grpname = sprintf("grp%d", ptnum); i think. edit: ach, rdg was quicker Edited November 6, 2008 by eetu Quote Link to comment Share on other sites More sharing options...
Aearon Posted November 6, 2008 Author Share Posted November 6, 2008 ah yeah great, much better thanks guys Quote Link to comment Share on other sites More sharing options...
Aearon Posted November 6, 2008 Author Share Posted November 6, 2008 hm... weird stuff happening now. i have this code: printf("grp%d\n",ptnum); addgroup(sprintf("grp%d", ptnum),ptnum); the printf generates the expected output (grp0,grp1,...,grp1042) i have 1043 points so everything seems correct but the groups created look like this: 256 points in grp0 256 points in grp256 256 points in grp768 19 points in grp1024 Quote Link to comment Share on other sites More sharing options...
eetu Posted November 6, 2008 Share Posted November 6, 2008 Interesting. My bet is this is caused by the parallel SIMD nature of how vex is executed. How do you get "ptnum"? eetu. Quote Link to comment Share on other sites More sharing options...
Aearon Posted November 6, 2008 Author Share Posted November 6, 2008 hm possible. maybe it executes blocks of 256 points at a time? interesting! ptnum is just the global var. the two lines are all the code there is. Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted November 6, 2008 Share Posted November 6, 2008 hm possible. maybe it executes blocks of 256 points at a time? interesting!ptnum is just the global var. the two lines are all the code there is. Looks like the optimizer thinks some part of your code is not worthy of inclusion Anyway, this hack seems to work (tried it in an InLine VOP inside a VopSop): if(!ptnum) { int i; for(i=0;i<Npt;i++) { addgroup(sprintf("grp%d",i),i); } } Quote Link to comment Share on other sites More sharing options...
rdg Posted November 6, 2008 Share Posted November 6, 2008 why: if(!ptnum) { Is ptnum set later to execute it just once? Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted November 6, 2008 Share Posted November 6, 2008 why: if(!ptnum) { Is ptnum set later to execute it just once? Not sure I understand the question. My thought behind it was that even if a bunch of threads (or "virtual processors" in SIMD) were spawned, one per point, that conditional would still only be true for just one of them. And ptnum is only referenced that one time (the local variable "i" takes over after that). Quote Link to comment Share on other sites More sharing options...
rdg Posted November 6, 2008 Share Posted November 6, 2008 oh. I missed ptnum being a global variable ... 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.