Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.pascal.misc > #2425

About the Active object pattern..

From Horizon68 <horizon@horizon.com>
Newsgroups comp.lang.pascal.misc
Subject About the Active object pattern..
Date 2019-06-29 15:24 -0700
Organization A noiseless patient Spider
Message-ID <qf8of6$tsm$5@dont-email.me> (permalink)

Show all headers | View raw


Hello...


About the Active object pattern..

I think the proxy and scheduler of the Active object pattern are 
embellishments, not essential. The core of the idea is simply a queue of 
closures executed on different thread(s) to that of the client, and here
you are noticing that you can do the same thing as the Active object 
pattern and more by using my powerful "invention" that is: An efficient 
Threadpool engine with priorities that scales very well that you can 
download from here:

https://sites.google.com/site/scalable68/an-efficient-threadpool-engine-with-priorities-that-scales-very-well


This Threadpool of mine is really powerful because it scales very well 
on multicore and NUMA systems, also it comes with a ParallelFor()
that scales very well on multicores and NUMA systems.

Here is the explanation of my ParallelFor() that scales very well:

I have also implemented a ParallelFor() that scales very well, here is 
the method:

procedure ParallelFor(nMin, nMax:integer;aProc: 
TParallelProc;GrainSize:integer=1;Ptr:pointer=nil;pmode:TParallelMode=pmBlocking;Priority:TPriorities=NORMAL_PRIORITY);

nMin and nMax parameters of the ParallelFor() are the minimum and 
maximum integer values of the variable of the ParallelFor() loop, aProc 
parameter of ParallelFor() is the procedure to call, and GrainSize 
integer parameter of ParallelFor() is the following:

The grainsize sets a minimum threshold for parallelization.

A rule of thumb is that grainsize iterations should take at least 
100,000 clock cycles to execute.

For example, if a single iteration takes 100 clocks, then the grainsize 
needs to be at least 1000 iterations. When in doubt, do the following 
experiment:

1- Set the grainsize parameter higher than necessary. The grainsize is 
specified in units of loop iterations.
If you have no idea of how many clock cycles an iteration might take, 
start with grainsize=100,000.

The rationale is that each iteration normally requires at least one 
clock per iteration. In most cases, step 3 will guide you to a much 
smaller value.

2- Run your algorithm.

3- Iteratively halve the grainsize parameter and see how much the 
algorithm slows down or speeds up as the value decreases.

A drawback of setting a grainsize too high is that it can reduce 
parallelism. For example, if the grainsize is 1000 and the loop has 2000 
iterations, the ParallelFor() method distributes the loop across only 
two processors, even if more are available.

And you can pass a parameter in Ptr as pointer to ParallelFor(), and you 
can set pmode parameter of to pmBlocking so that ParallelFor() is 
blocking or to pmNonBlocking so that ParallelFor() is non-blocking, and 
the Priority parameter is the priority of ParallelFor(). Look inside the 
test.pas example to see how to use it.




Thank you,
Amine Moulay Ramdane.

Back to comp.lang.pascal.misc | Previous | Next | Find similar | Unroll thread


Thread

About the Active object pattern.. Horizon68 <horizon@horizon.com> - 2019-06-29 15:24 -0700

csiph-web