|
From: Brad C. <br...@cr...> - 2011-04-04 16:59:16
|
Hi Max -- There is no direct equivalent to pointer swapping at the user level in Chapel since Chapel arrays are not pointers and in general two arrays may have different memory layouts that would prevent this style of implementation. That said, there are cases where the implementation could implement the equivalent of a pointer swap as an optimization: for example, when the swap operator ( <=> ) is applied to two arrays declared over the same domain, the underlying memory buffers used to implement those arrays could be swapped. Implementing this optimization would be a joint effort between the compiler and the domain map author (the person implementing the array's implementation). Unfortunately, we do not have support for this optimization in our compiler as of yet. In the meantime, you can either use an array of arrays as suggested in Raphael's follow up mail (or equivalently, a pair of array aliases) in order to make the swapping logical; or you could unroll your loop manually two times and have each be written in terms of one of the arrays. Neither is quite as elegant as the proposed array swap optimization above. Note that the C you propose isn't quite identical to the Chapel code in that the Chapel is only exchanging the interiors of the two arrays whereas the C code is exchanging the entire array contents. This isn't a problem if the boundary conditions are set up identically in both arrays. If we had done that in Chapel, we could have written the assignment as: X = XNew; or used the swap operator as follows: X <=> XNew; -Brad >> // update X with next approximation >> X[ProblemSpace] = XNew[ProblemSpace]; > > If we were writing this in C, we would simply swap the pointers, and > save ourselves the memory copy. > >> float* temp; >> temp = X; // assume X and XNew are of type float* >> X = XNew; >> XNew = temp; > > Is there good way to do this in Chapel? I thought of a workaround where > we use a single large array and alternate having X be at the beginning > of it, or half-way down (with XNew visa-versa) so that there is no > memory transfer, but this seems a bit of a hack. > > thanks, > > Max > > ------------------------------------------------------------------------------ > Create and publish websites with WebMatrix > Use the most popular FREE web apps or write code yourself; > WebMatrix provides all the features you need to develop and > publish your website. http://p.sf.net/sfu/ms-webmatrix-sf > _______________________________________________ > Chapel-users mailing list > Cha...@li... > https://lists.sourceforge.net/lists/listinfo/chapel-users > |