Single threaded execution when stocknum == 0

What are the coding requirements for automatic single-threaded execution during stocknum 0?

Per the manual, this works:

if (Status("stocknum") == 0)
{
  StaticVarSet(...)
}

Does this also cause single threaded execution during stocknum 0?

stocknum = Status("stocknum");
... hundreds of lines of other code ...
if (stocknum == 0)
{
  StaticVarSet(...)
}

If something is written in the manual, please follow the advice given. Any user “original inventions” either won’t work or will stop working.

The documentation is a specification. It works as specified. It does not work as not specified.

@Tomasz Thank you for the prompt reply. A couple follow-up questions.

  1. Is it okay to have multiple such code constructs in a large AFL program?

  2. Could you clarify the start and end of the single threading boundary? I assume it is all code inside the curly braces code block when guarded by the "if (Status("stocknum") == 0)", but maybe the entire AFL is single-threaded?

@Steve

The whole code (from the top to the bottom) is run single-threaded for the very first Symbol. For that reason, there is no need to have multiple checks like this in the code. One is enough.

A quote from https://www.amibroker.com/guide/h_multithreading.html :
AmiBroker detects such statement and runs very first symbol in one thread only, waits for completion and only after completion it launches all other threads. This allows things like setting up static variables for use in further processing, etc.

By the way, if you really need to, you can limit the number of threads that will be used during entire Exploration (or any other multi-threaded Analysis operation). For example if you want strictly sequential execution (single-threaded) you can achieve that by placing the following pragma call at the top of the formula:

Of course such or similar modifications should be generally avoided, as they make the formula run (much) slower.

4 Likes

@Milosz Thank you for the explanation.

1 Like