Limits of multi-threading

Tags: #<Tag:0x00007f80469c13f0>


I posted new article in the Knowledge Base called

Limits of multi-threading

This took quite a bit of time to write but at least should answer some questions that surface from time.


Tomasz, thank you very much for this really interesting article :+1: :slight_smile:

I am sure, lots of AB users really appreciate your willingness to share your knowledge and expertise. Each article from the AB Knowledge Base gives us an opportunity to learn something new.

Reading them should be obligatory :bangbang:



You’re welcome. If you or anybody have questions about the article ask here.

On the feedback center someone suggested creating some kind of benchmark procedure in AmiBroker so people could run it against their machines and post it on line so some kind of AmiBroker’s hardware performance database would be created. It is not bad idea, however user formulas vary a lot and it would be quite difficult to come up with some formula that “blends it all” in some representative way.


Thanks Tomasz - great article and a good problem to tackle on as it seems to created a lot of confusion among the members.

BTW - speaking about multithreading if some user has access to both Ryzen and the new Coffee Lake ( on a similar machine ) - perhaps he could run few tests on a simple formulas and a bit more CPU intense ( nested percentiles ect… ) to see how they compare on Amibroker. Anyone ? :slight_smile:


@Tomasz Thank you for the detailed examples. Why does the info tab show the worker thread timings with two measurements? When will we see two different values here?

worker threads: 3.26/3.26


I have an afl script output my exploration result to a csv file. However, when I am compare the exploration results and file output, the file output consistently has missing record. The missing record happens randomly. This problem is fixed when I restrict to single thread i.e. #pragma maxthreads 1

Here is the file output script in my AFL.

if ( Status( "stocknum" ) == 0 )
	//Write lable once at the first line.
	fh = fopen( "c:\\Users\\Peter\\Desktop\\Amibroker_Output_file\\"+file_name, "w",shared=True);
	fputs("Ticker,Date,Rank\n", fh);
	//Append subsequent line to the output file.
	fh = fopen( "c:\\Users\\Peter\\Desktop\\Amibroker_Output_file\\"+file_name, "a",shared=True);


You are not checking the result of fopen. You can’t assume that file is open. You have to always check this. fopen returns NULL if failed and you need to check that as instructed in the KB:


The Limits of multi-threading article mentioned step 3:

  1. execution of your formula (in backtest for example it means first phase of backtest run, done on every symbol)

Can we safely assume that, for a multi-thread analysis, that only one ticker/symbol is operated on at a time? Or is it possible that the same ticker/symbol will be concurrently processed by multiple threads?


In the manual at the very top it is very clearly said (right in the beginning of section “Understanding how multithreading is implemented”) how many threads per symbol are used. It is all there, in the users guide. Explained in great detail. Really I spent countless number of hours writing the manual. All the knowledge that you ever need to know about AmiBroker is in the manual. I would argue that AmIBroker docs are most detailed docs, down to the bare metal, ever written, even if some people say it is “not good”. Maybe it is so because it lacks stylistic “blah blah blah” sugar found elsewhere. But please do READ entire page from Users guide, not only first sentence, because later on in the document that is one exception listed (namely: Individual optimization).