Hello,
A couple of numbers for parallel execution (OpenMP, Visual C++ 2005, 32 bit
code)
Parameters:
number of array elements = 10000 (equivalent to 40 years of EOD data)
number of repetitions = 50000
Number of operations: 10000 * 50000 = 500 million.
number of cores = 2 (AMD Athlon x64 x2 3800)
The experimental code does two-operand arithmetic operation on every
element of two arrays and stores the result in 3rd array.
This is most typical (most frequently performed) operation in any AFL
formula.
(actual C code used is included below)
Results for various arithmetic operations:
1.
Operation: ADDITION: x[i] = y[i] + z[i];
Parallel execution: 0.968 sec
Sequential execution: 0.953 sec (yes sequential single core is quicker!)
2.
Operation: MULTIPLICATION: x[i] = y[i] * z[i];
Parallel execution: 0.985 sec
Sequential execution: 0.953 sec (yes sequential single core is quicker!)
3.
Operation: DIVISION: x[i] = y[i] / z[i];
Parallel execution: 1.531 sec (2-core advantage: 30%)
Sequential execution: 2.000 sec
Division as we see is more complex operation and CPU needs more
cycles to perform it compared to addition and multiplication,
therefore multiple cores do not fight for memory access as much as
in previous cases. Still only 30% speed up is achieved.
4.
Operation: TWO SINE and ADDITION: x[i] = sin( y[i] ) + sin( z[i] );
Parallel execution: 11.98 sec (2-core advantage: 95%)
Sequential execution: 23.423.4 sec
Sine is much more complex operation and CPU needs LOTS of cycles to
perform it compared to addition and multiplication,
therefore multiple cores do not fight at all for memory access.
Now 95% speed increase was achieved (almost ideal).
Unfortunatelly trigonomeric functions and other cpu-cycle-hungry stuff
is a rarity in practice.
These are idealized cases because in real formula there are not as many
as 50000 repretitions of the same calculation therefore parallel thread
setup
code would increase the timings for parallel execution more.
Also EOD users very rarely use as much as 10000 bars (40 years).
Parallel execution benefits for smaller arrays are not as significant.
For example when most parallel-friendly case 4 (2 * sine and addition)
is applied to array of 1000 bars
(4 years) the timings are 1.578/2.156 - thats only 36% speedup
(compared to 95% with 10k bars).
With 250 bars (1 year of EOD data) sequential single-core execution is
faster
(timings 0.735sec - parallel vs. 0.515sec - sequential)
The results above are due to two main factors:
1. thread management code that takes extra time that is required to manage
more than one core
(BTW: in case you are curious if it is optimal or not -
I did not write the thread management code - Microsoft written it inside
OpenMP implementation,
I have seen the disassembly and it is pretty minimal)
2. limited memory bandwidth (visible in case 1 and 2) - when processors
execute code FASTER
than memory is able to deliver/store the data. Then adding extra cores
actually makes things worse.
Note that example used three 10000 element arrays (each 40KB in size) so
memory used was 120KB only. Note that 120KB fits inside the L2 on-chip cache
!
In case 1 one iteration takes about 1.9 nanoseconds. L2 cache bandwidth is
limited to 9.6GB/sec.
(http://www.digit-life.com/articles2/cpu/rmmt-l2-cache.html)
Given that one 32 bit (4 bytes) on-chip cache read or write operation takes
about 0.42 nanoseconds. With 2 reads and 1 write per iteration, the cache
memory access alone needs 1.26 ns. That's over 66% of loop execution time
(that's including not only addition but incrementing loop
counter and conditional jump). Clearly CPU is waiting for memory.
Note that once data does not fit inside the cache the memory times gets 10
times worse.
Best regards,
Tomasz Janeczko
amibroker.com
void test( void )
{
clock_t start, end;
#define size 10000
static float x[ size ];
static float y[ size ];
static float z[ size ];
start = clock();
for( int k = 0; k < 50000; k++ )
{
#pragma omp parallel for
for(int i = 1; i < size - 1; ++i)
x[i] = y[i] + z[i];
}
end = clock();
printf("parallel run: %g\n", 1.0*(end-start)/CLOCKS_PER_SEC );
start = clock();
for( int k = 0; k < 50000; k++ )
{
for(int i = 1; i < size - 1; ++i)
x[i] = y[i]) + z[i];
}
end = clock();
printf("sequential run: %g\n", 1.0*(end-start)/CLOCKS_PER_SEC );
}
----- Original Message -----
From: "Tomasz Janeczko" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, November 23, 2006 10:39 AM
Subject: Re: [amibroker] Re: Can anyone explain Why AmiBrokers instead of
Metastock
> Hello,
>
> First: I was speaking about paralellization of much finer
> operation (single array addition), not entire optimization.
>
> This makes it simply uncomparable to what you are talking about.
> The percentage overhead of using multiple cores to do operation that
> takes milliseconds can not be compared to overhead of
> using multiple machines to do the operation that takes seconds
> (6 orders of magnitude difference in execution time).
>
> Second: on multiple machines you have separate, dedicated RAM
> and no conflicts between CPUs accessing the same RAM.
>
> Of course if we compared apples to apples (i.e. parallel
> execution of *optimization* only) then the overhead would be similar
> (or lower).
>
> There are very few people who run very long optimizations,
> on the other hand every ordinary buyer of dual core box expects
> immediate 2x performance which is not the case
> for reasons outlined in earlier e-mail (in short: parallelization is
> worthwhile
> either for tasks that fit entirely in CPU caches OR tasks that are long
> enough (like optimization) so time spent on thread management is
> much smaller percentage of entire time needed to complete the task).
>
> That was the bottom line of my previous e-mail: to cool down expectations
> ordinary people have thinking that dual core means or will mean 2x speed.
> The reality is pretty far from it.
>
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message -----
> From: "Fred" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Wednesday, November 22, 2006 11:49 PM
> Subject: [amibroker] Re: Can anyone explain Why AmiBrokers instead of
> Metastock
>
>
>> TJ,
>>
>> I could be wrong because I haven't tried to write something to
>> utilize multiple cpu/core configurations within the same box, but I
>> know from writing parts of IO that allow for cooperative optimization
>> between multiple boxes that one can keep the overhead very low and I
>> would think ?! that there is a much higher chance for overhead to be
>> considerably higher using multiple boxes then multiple cpu's/cores on
>> the same box.
>>
>> --- In [email protected], "Tomasz Janeczko" <[EMAIL PROTECTED]>
>> wrote:
>>>
>>> Hello,
>>>
>>> To take advantage of any CPU feature the program has to be
>> specifically
>>> built for given feature.
>>> No gain is "automatic". You need to code specifically for given
>> feature.
>>>
>>> When it comes to 64 bit - the source code had to be adjusted
>>> in several hundreds of lines where incompatiblities were found.
>>> Plus it had to be compiled with new 64 bit compiler and run on 64
>> bit computer
>>> running 64 bit version of Windows.
>>>
>>> Multi-core support is similar, although more complex story -
>>> the code needs to be restructured significantly. Also even if you
>> restructure
>>> the code you may find out that there is no gain because the speed
>>> is limited not by execution of CPU but by memory access because
>>> modern CPUs can often calculate more data than RAM is able to
>> read/store.
>>> Also thread switching / synchronization make eat all theoretical
>> gains.
>>> For example if you make array addition parallel it will run SLOWER
>> on dual
>>> core than on single core unless array has hundreds of thousands
>> bars because
>>> of thread management overhead.
>>> Multiple CPU/Core is only able to run at full speed if data and
>> code can
>>> fill entirely within integrated on-die processor cache. This is
>> rarely the case
>>> when it comes to data of thousands of symbols each having thousands
>> of data bars.
>>> As soon as processor needs to access RAM it simply needs to wait.
>>> Single core can be amazingly fast when processing arrays and it is
>> much
>>> faster than RAM. Code compiled with SSE instructions enabled (x64
>> version does that),
>>> use SIMD instructions that can add/multiply 4 numbers in one CPU
>> cycle.
>>> This is way way faster than RAM speed so processor wastes time
>> waiting for
>>> RAM access if data are not fully present in CPU cache. And adding
>> second core
>>> does not help if RAM is bottleneck.
>>> What I am talking about here is not theoretical stuff but something
>> I actually
>>> measured on internal testing versions of AB that used parallelized
>> parts.
>>>
>>> Current production versions of AB do not use multiple cores.
>>>
>>> It will change sooner or later but currently I give no dates.
>>>
>>> Best regards,
>>> Tomasz Janeczko
>>> amibroker.com
>>> ----- Original Message -----
>>> From: mark keitel
>>> To: [email protected]
>>> Sent: Wednesday, November 22, 2006 8:26 PM
>>> Subject: RE: [amibroker] Re: Can anyone explain Why AmiBrokers
>> instead of Metastock
>>>
>>>
>>> Thomas,
>>>
>>>
>>>
>>> If 64 bit adds 25% to AB's speed
>>>
>>> How much will the Dual Core add?
>>>
>>>
>>>
>>> Mark
>>>
>>>
>>>
>>>
>>> --------------------------------------------------------------------
>> ----------
>>>
>>> From: [email protected]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Tomasz Janeczko
>>> Sent: Wednesday, November 22, 2006 11:41 AM
>>> To: [email protected]
>>> Subject: Re: [amibroker] Re: Can anyone explain Why AmiBrokers
>> instead of Metastock
>>>
>>>
>>>
>>> Actually 64 bit itself adds 25% to AmiBroker speed (AFL
>> execution).
>>> http://www.amibroker.com/x64/
>>>
>>> Best regards,
>>> Tomasz Janeczko
>>> amibroker.com
>>> ----- Original Message -----
>>> From: "Fred" <[EMAIL PROTECTED]>
>>> To: <[email protected]>
>>> Sent: Wednesday, November 22, 2006 5:18 PM
>>> Subject: [amibroker] Re: Can anyone explain Why AmiBrokers
>> instead of Metastock
>>>
>>> > I'd leave it ...
>>> >
>>> > Speed - Although there are 32 & 64 bit versions of the program,
>> 64
>>> > bit in and of itself is not likely to add a lot of speed to ANY
>>> > program. As far as the programs speed is concerned, this is the
>>> > single biggest reason I tossed TradeStation in favor of
>> AmiBroker
>>> > years ago. In this regard, MetaStock isn't even a close 3rd ...
>>> >
>>> > Dual CPU/Core - There is a planned enhancement to be able to
>> utilize
>>> > multuiple CPU's / Cores for AmiBroker optimization. TJ would
>> have to
>>> > be the one to speak to when that would most likely be
>> available.
>>> > There are already add in products that allow multiple machines
>> to
>>> > cooperate in this process.
>>> >
>>> > Ease of Use - I find AmiBroker to be no better or worse in this
>>> > regard then any other platform, but I suspect different people
>> will
>>> > see this one differently.
>>> >
>>> > Add Ins / PlugIns - I personally find it extremely unlikely
>> that
>>> > other platforms are as flexible in this regard as AmiBroker.
>> One can
>>> > write their own DLL's in C++ and/or other languages if one
>> desires
>>> > and use OLE/Automation to drive AmiBroker in almost any way one
>>> > wants.
>>> >
>>> > --- In [email protected], "Natasha ~~!!!"
>>> > <ghostship.blackparrot@> wrote:
>>> >>
>>> >> hello,
>>> >>
>>> >> Depends why u are buying the software . If u are buying to
>> make
>>> > money on
>>> >> the stock markets
>>> >> by trading then amibroker will make you lots of money and this
>>> > would be
>>> >> extremely good value for money .
>>> >>
>>> >>
>>> >> Else u can buy either , it makes no difference .
>>> >>
>>> >> I am assuming that one would make money on the stock markets
>>> > if one has
>>> >> a good trading system adn
>>> >> strategy and ease of operation of both looking at charts and
>>> > designing a
>>> >> system to suit your trading
>>> >> mentality and bank balance.
>>> >>
>>> >> Of couse this is my take and it is mine .Take it or leave it
>>> > is your
>>> >> take .
>>> >>
>>> >> ````` Natasha !!!!!!
>>> >>
>>> >>
>>> >> On 11/22/06, mytakeismine <mytakeismine@> wrote:
>>> >> >
>>> >> > Why AmiBrokers instead of Metastock?
>>> >> > Speed, ease of use, add-ins and plug-ins, richness and
>> maturity
>>> >> >
>>> >> > Speed, Is this 32bit or a 64bit program? will this benefit
>> from
>>> > dual
>>> >> > processors(smp)?
>>> >> >
>>> >> > Ease of use, Learning curve this verses Metastock, intuitive?
>>> >> >
>>> >> > Add-ins and plug-ins, Can you get more or less with this
>> verses
>>> >> > metastock?
>>> >> >
>>> >> > Intuitive, does it easily makes sence the way it was written
>>> > almost
>>> >> > anticipating your needs?
>>> >> >
>>> >> > I am asking this here and at metastock, I have known about
>>> > Metastock
>>> >> > for sometime and am just hearing for the first time about
>>> > AmiBrokers
>>> >> >
>>> >> > Thanks
>>> >> > mytakeismine
>>> >> >
>>> >> >
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Warm Regards;
>>> >> `````` Natasha !!!
>>> >>
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > Please note that this group is for discussion between users
>> only.
>>> >
>>> > To get support from AmiBroker please send an e-mail directly to
>>> > SUPPORT {at} amibroker.com
>>> >
>>> > For NEW RELEASE ANNOUNCEMENTS and other news always check
>> DEVLOG:
>>> > http://www.amibroker.com/devlog/
>>> >
>>> > For other support material please check also:
>>> > http://www.amibroker.com/support.html
>>> >
>>> > Yahoo! Groups Links
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>>
>>
>>
>>
>>
>>
>> Please note that this group is for discussion between users only.
>>
>> To get support from AmiBroker please send an e-mail directly to
>> SUPPORT {at} amibroker.com
>>
>> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
>> http://www.amibroker.com/devlog/
>>
>> For other support material please check also:
>> http://www.amibroker.com/support.html
>>
>> Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>
>
> Please note that this group is for discussion between users only.
>
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
> Yahoo! Groups Links
>
>
>
>
>
>