Problems with Multithreading

Hello everyone, I’m having problems with multithreading. I adapted the B4d example to my task, without MT, the calculation of 10,000 neutrons is an hour. I made a version of geant4 with multithreading, but the calculation time does not decrease. In the mac file I insert the line “/run/numberOfThreads 6”, but when I run the mac file, I get an error:

Macro file for example B4

Can be run in batch, without graphic

or interactively: Idle> /control/execute run1.mac

Change the default number of workers (in multi-threading mode)

/run/numberOfThreads 6
***** Illegal application state </run/numberOfThreads 6> *****

***** Batch is interrupted!! *****

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
issued by : G4UImanager::ApplyCommand
Command aborted (200)
Error code : 200
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------
This link - Google Drive for my example.
TY for help.

Dear SiDAiftp,

Hello! I downloaded your code. I changed a line ‘/run/numberOfThreads 12’ of ‘run1.mac’ file into ‘/run/numberOfThreads 6’ and It worked… It took several seconds, and I think there is no problem with the code.
I attach run1.mac file and GEANT4 result file.

Best regards,
Jaeyoung Jeong


Have a look at the following post

Hello dear Jaeyoung Jeong, unfortunately, I still get the same error, I also change the number in when replacing the number of cores, the error remains, only the number changes in the error, the line with run is before initialize. Maybe the problem is in the assembly with MT?

the line with run is before initialize

Are you running in batch or interactive mode?

In interactive mode in your main it runs the init_vis macro which has a /run/initialize command, so in interactive mode you cannot set the Nb of threads…, BUT it should use 12 threads…

I’m sorry to hear that the error occurs yet.

I think the problem may be caused during compilation.

Did you set ‘DGEANT4_BUILD_MULTITHREADED=ON’ when you compile Geant4 with CMake?

As there is no problem with the code working on my Desktop, I doubt that there may be an error during installation.

Best regards,

Jaeyoung Jeong

It turns out that you need to make changes to init_vis, include a line with run and compile, and so on?

Yes, modeMT_ON, when i compile.

I am not sure I understand what you mean…

The simplest way would be to run in batch mode.

If you want the interactive mode without compiling, then you can run the program with the -t flag to set the desired threads, but then you have to remove/comment the numberOfThreads command from the macro that you run.

Another way would be to comment the hard coded running of the macros from the main, recompile and run whatever macro you want by hand in interactive or not mode…

There are other possibilities also… But you have to be careful not to issue a numberOfThreads command after you have initialized!

Sorry im newbe in geant4 , can u explain or write example how run with -t flag? I just open run1.mac in interface window.

As I wrote before the default nb of threads is 12.
If you want to change it (in interactive mode) without recompiling or changing your init_vis macro you can run the program from the command line like (you can replace 6 with the number of threads you want to set)

exampleB4d -t 6

In order to run run1.mac, you have to delete or comment the line with the numberOfThreads command, otherwise you will get the error message of your first post.

Take a look at this, I ran it through the command line:
./exampleB4d - t 12
And opened my mac file, without the run/numberofthreads line.
I see that all 12 threads are used in the calculations, but in htop the threads are used in turn up to one hundred percent and not all at once, how can I explain this?
intel i5 10400f 6x2.9.

My guess would be that this is because of the visualization… (sorry, but I cannot test it at the moment).

Try running in batch mode like (given that your mac file is run1.mac)

exampleB4d -t 12 -m run1.mac

Does it look better?

In general, I have noticed that visualization slows down the simulation. I would advise you not to use it for the “real” simulation, but only during the initial steps when you set your geometry/source/…

Cool, it look better, u right !!! Ty very much!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.