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 B4d.zip - Google Drive for my example.
TY for help.
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.
Hello dear Jaeyoung Jeong, unfortunately, I still get the same error, I also change the number in example.cc 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?
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…
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!
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?
CPU
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/…