March 10, 2015 Re: Parallelization of a large array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On 03/10/2015 03:34 PM, Ali Çehreli wrote: > It is possible by accessing the actual range by chunks: Sorry, I posted a jumbled program that does not compile. The following is the program that does NOT use taskPool.map. I am also changing the name of a variable because the local 'chunks' looked like std.range.chunks. import std.stdio; import std.algorithm; import std.parallelism; import std.range; import std.conv; void main() { const size_t elementCount = 895640; int[] a = iota(elementCount) .map!(i => i.to!int) .array; const chunkSize = a.length / taskPool.size; auto ch = a.chunks(chunkSize); bool[] results = new bool[ch.length]; foreach (i, chunk; ch.parallel) { results[i] = chunk.canFind(895639); } writeln(results.canFind(true) ? "Yes" : "No"); } Ali |
March 10, 2015 Re: Parallelization of a large array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Tuesday, 10 March 2015 at 22:43:08 UTC, Ali Çehreli wrote:
> The following is the program that does NOT use taskPool.map. I am also changing the name of a variable because the local 'chunks' looked like std.range.chunks.
>
> import std.stdio;
> import std.algorithm;
> import std.parallelism;
> import std.range;
> import std.conv;
>
> void main()
> {
> const size_t elementCount = 895640;
> int[] a = iota(elementCount)
> .map!(i => i.to!int)
> .array;
>
> const chunkSize = a.length / taskPool.size;
> auto ch = a.chunks(chunkSize);
> bool[] results = new bool[ch.length];
>
> foreach (i, chunk; ch.parallel) {
> results[i] = chunk.canFind(895639);
> }
>
> writeln(results.canFind(true) ? "Yes" : "No");
> }
Thanks. This code will help me.
|
March 11, 2015 Re: Parallelization of a large array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Tuesday, 10 March 2015 at 22:37:29 UTC, Ali Çehreli wrote:
> On 03/10/2015 03:16 PM, Meta wrote:
>
> > Just add a condition variable.
> >
> > import std.stdio;
> > import std.algorithm;
> > import std.parallelism;
> >
> > void main() {
> >
> > int b = 2;
> >
> > auto a = [1, 2, 2, 3];
> >
> > if (find(a, b).length != 0)
> > writeln("Yes_");
> >
> > auto found = false;
> >
> > foreach (elem; a.parallel)
> > if (!found && elem == b)
> > {
> > writeln("Yes");
> > found = true;
>
> I thought about the same solution but then realized that it's a race condition, which needs to be taken care of. It's true that the value always changes from false to true but still...
>
> > }
> > }
>
> Ali
Yes, it's a non-deterministic solution, but I don't think it matters all that much as we don't care which element fulfills the criterion, just that such an element exists.
That's my reasoning, anyway. I know next to nothing about parallel processing.
|
March 11, 2015 Re: Parallelization of a large array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli Attachments:
| On Tue, 2015-03-10 at 15:34 -0700, Ali Çehreli via Digitalmars-d-learn wrote: […] > We can hope to make it simpler by taking advantage of parallel map but it requires a static local function or a global function (a lambda cannot be used): […] Is there a reason for excluding lambdas, it a priori sounds like a bug. > -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
March 11, 2015 Re: Parallelization of a large array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On 03/11/2015 01:07 AM, Russel Winder via Digitalmars-d-learn wrote: > On Tue, 2015-03-10 at 15:34 -0700, Ali Çehreli via Digitalmars-d-learn > wrote: > […] >> We can hope to make it simpler by taking advantage of parallel map but >> it requires a static local function or a global function (a lambda >> cannot be used): > […] > > Is there a reason for excluding lambdas, it a priori sounds like a bug. This is a current language implementation issue because there is just one context pointer. Parallel map is a member function that takes its function as an 'alias' template parameter: https://issues.dlang.org/show_bug.cgi?id=5710 Ali |
March 11, 2015 Re: Parallelization of a large array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli Attachments:
| On Wed, 2015-03-11 at 07:10 -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 03/11/2015 01:07 AM, Russel Winder via Digitalmars-d-learn wrote: > > On Tue, 2015-03-10 at 15:34 -0700, Ali Çehreli via Digitalmars-d-learn > > wrote: > > […] > >> We can hope to make it simpler by taking advantage of parallel map but it requires a static local function or a global function (a lambda cannot be used): > > […] > > > > Is there a reason for excluding lambdas, it a priori sounds like a bug. > > This is a current language implementation issue because there is just one context pointer. Parallel map is a member function that takes its function as an 'alias' template parameter: > > https://issues.dlang.org/show_bug.cgi?id=5710 Sadly the conversation seems to summarized as: There is a major problem. This problem must be fixed. None of the solution proposed so far are perfect in all cases. Let's leave the mess as is not even trying to fix at least some of the worst problems. No more debate. I haven't thought about this much, but my initial reaction to this is that a language that has functions and closures/delegates where a closure/delegate is not substitutable for a function, has real problems. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
Copyright © 1999-2021 by the D Language Foundation