Hi,
>> I'd definitely like to see something like this, too. I actually just used
>> C-style
>> preprocessor directives in my code and ran it through C preprocessor before
>> handing it to chapel compiler.
>
> Yeah. that's a fine workaround as long as nothing in your Chapel code causes
> cpp to break (many implementations are very C-centric and will warn about
> legal Chapel code).
I didn't get any warnings, I just had to remove all line starting with # from
the generated code. I guess that writing a small preprocessor in Perl or
something wouldn't be a big task, though, just a simple regex-based processor
could be useful.
>> Well, I will be able to work around this somehow for now....Currently I
>> have to
>> call the constructor like following:
>>
>> const tbl: [LocaleSpace] real = 1.0;
>> const domMap = if useBlockDist then
>> new dmap(new Block(...))
>> else
>> new dmap(new MyBlock(new
>> MyPolicy(relCutTable=tbl, ...)));
>>
>> Now tbl is defined whether I use block dist or MyBlock (I hope compiler
>> optimizes that away?). How could I write that so that I could factor tbl
>> out?
>
> What about pushing the entire else clause into a helper function, declaring
> tbl as
> a local variable in that helper function and passing it into the MyPolicy
> constructor
> from there? The helper could either return the new MyPolicy object, or it
> could
> create the entire new MyBlock object (or, presumably even the new dmap)?
Well, this really isn't a big problem, since relCutTable will very rarely be
filled with 1.0s ans more or less complex routines are needed to determine it.
I was just interested if there was some elegant, one line way of dealing with
that problem for future reference.
>> Also, is there any kind of swap-by-reference routine in Chapel? Ie. I have
>> two arrays,
>> u and u0. Now I want u0 to get contents of u, and what u gets is of no
>> importance.
>> Writing u0=u (or u0<=>u ) would copy by value causing unnecessary overhead.
>> I'm looking for something similar like how one would swap pointers in C...
>> I think I
>> could wrap arrays inside classes, but that would make code harder to read
>> and maintain...
>
> We don't supply this by default because the user's view of an array in Chapel
> is not
> memory oriented, it's index->variable oriented (and, in general, the
> optimization won't
> make sense unless the two arrays share the same domain and domain map and that
> domain map stores all arrays identically and there aren't any outstanding
> references to
> the array.
I think that this kind of cases are fairly frequent, at least in kind of work
I'm used to. Also would it be necessary not to have outstanding references to
the array?
I've postulated that it'd be possible to extend the swap overload for arrays
> in modules/internal/ChapelArray.chpl to handle this case:
>
> //
> // Swap operator for arrays
> //
> inline proc <=>(x: [], y: []) {
> forall (a,b) in zip(x, y) do
> a <=> b;
> }
>
> but haven't ever taken that on myself. As you say, one could do this by
> bypassing
> the official array interface and making calls into, say, a helper function
> with the
> [My]BlockArr class that did the swapping, but I don't believe that any of our
> current
> domain maps export such a routine. I think in practice what people tend to
> do is
> to pass the two arrays into a helper routine, swapping the order of the
> arguments
> to get an A, B vs. B, A kind of effect, or to create an array [1..2] of
> arrays and use
> indices into the outer array to get the same effect.
I was thinking of the latter approach. Also a generic ring buffer
implementation would be useful in cases like this. I almost started writing
one, storing in array N elements of type T. However, I couldn't figure a way to
write a method getCurrent(), which would return current element in buffer, so
that it would always return a reference. Or any other clever way so user could
always modify the current element in ring buffer.
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users