Re: Re: Speeding Up Realtime Visualization

*To*: mathgroup at smc.vnet.net*Subject*: [mg84289] Re: [mg84273] Re: Speeding Up Realtime Visualization*From*: Sseziwa Mukasa <mukasa at jeol.com>*Date*: Mon, 17 Dec 2007 19:19:07 -0500 (EST)*References*: <200712170803.DAA05659@smc.vnet.net>

On Dec 17, 2007, at 3:03 AM, Will wrote: > Ok, great! It has sped it up a bit. Thanks. > > I think my problem is actually *how* I'm forming the matrix which > I'm viewing, not actually visualizing the thing. > > Here's the code where I think I'm going wrong: > > (this is a double buffer setup) > > While[True, > For[i = 2, i < length, i++, > For[j = 2, j < length, j++, > > x[[c,i,j]] = (functions of x[[p,i,j]] & y[[p,i,j]]); > > y[[c,i,j]] = (functions of x[[p,i,j]] & y[[p,i,j]]); > > ] > ] > If[p == 1, c = 1; p = 2, c = 2; p = 1]; (c/p inverter) > ] > > Note that for each definition of x[[c,1,2]] and y[[c,1,2]], the > functions call 5-6 values from x[[p]] and/or y[[p]]. So I suspect > it's this array setup I have that's slowing down the execution. > > I've also tried setting up the definitions of the arrays via a > Compile function. Although this speeds it up a little more, it's > still no where near what I need/want it to be. Of course, I can > turn down my integrator step intervals to get the speed I want, but > the drop in quality is way too much. > > Any ideas? It's hard to say without more details, but at the level you've described the problem, perhaps it would be better to do all your computations using MapIndexed, or Array or something and do your assignment once to x[[c,Range[2,length],Range[2,Length]]] and y [[c,Range[2,length],Range[2,Length]]]. It may not improve anything or it may allow Mathematica to perform further optimization, in general large block transfers are more efficient than small memory copies but at the level of the Mathematica language it's hard to be sure how such a statement is going to be implemented. This technique would of course use more memory, but there's usually a time/space tradeoff in these situations anyway. Also to facilitate block memory transfers you may want to split x and y into x1, y1 and x2, y2 and reorganize your loop accordingly eg. While[True, For[i = 2, i < length, i++, For[j = 2, j < length, j++, x2[[i,j]] = (functions of x1[[i,j]] & y[[i,j]]); y2[[i,j]] = (functions of x1[[i,j]] & y1[[i,j]]); ] ]; For[i = 2, i < length, i++, For[j = 2, j < length, j++, x1[[i,j]] = (functions of x2[[i,j]] & y2[[i,j]]); y1[[i,j]] = (functions of x2[[i,j]] & y2[[i,j]]); ] ] ] Without details on how x[[c,i,j]] depends on x[[p,i,j]] and y [[p,i,j]] it's hard to see any options for improvement. Incidentally, why do you have an extra row and column in y and x? Regards, Ssezi

**References**:**Re: Speeding Up Realtime Visualization***From:*Will <secandum.oculi@gmail.com>

**Re: quadratic multiplication**

**RE: Mathematica 6 Documentation - how does one add to it?**

**Re: Speeding Up Realtime Visualization**

**Re: Re: Speeding Up Realtime Visualization**