Particular example in multithreading mode?

Hi Experts,

I want to know that can we run a particular example in multi threading mode ?
if yes, how it can be done for a particular example like B1 ?
since i have installed Geant4 without multi threading so how can i do that.
Thanks in advance!

you can do it in main program:

G4MTRunManager* runManager = new G4MTRunManager;
G4RunManager* runManager = new G4RunManager;

Thanks for your reply!

yes, i did this, but it is not running in multi threading mode after giving this lines of code.

so do i need to change something in installation because by doing so it is only running as same as it runs in single thread . i can’t see those threads as it shows when it runs in multi threading mode.

I tried it for the basics example B1 and i made all the changes in action initialization by writing build for master and also included header files.

also i was running this in batch mode , with run1.mac file where i mentioned all the commands needed for multi threading but till now it is not running in multi threading mode.

is there anything that i have to switch on before running the example ?

can you please help me with this.
Thanks in advance !

you need to recompile and reinstall grant4 with multithreading

in the same installation, can i reinstall it with multi threading or should i have to delete the first one and install Geant4 again with multi threading ?

If the directory in which you ran cmake, then make and make install is still present on the system, then you can go into that and run

$ make && make install

and it will recompile and re-install. If that original build directory isn’t present then yes, you’ll need to delete the existing install and re-build/install from scratch.

1 Like

Yes, it is there. i can do this.

one more question , if i do so then will i be able to run the same code in single thread (if i wish to or my code is not thread safe) after changing this installation to multi thread mode.

yes. in this case you would omit the #ifdef stuff, and select the type of the runmanager manually:

G4RunManager* runManager = new G4RunManager;

1 Like

okay thank you so much @weller @idrissi_abdelghani @bmorgan for the help.

when i am changing the installation for multi-threading then it is giving me this error. i am not getting this why this error is occurring attached image.
can you please help me with this. how can i resolve this issue.

Is the file it’s saying isn’t there: /usr/lib/x86_64-linux-gnu/ actually present on the system? It might be necessary to reinstall the packages providing that file and Qt5.

how can i do that ? how should i provide that file and Qt5 . can you please help me with this.
Thanks & Regards

First things first, is the file /usr/lib/x86_64-linux-gnu/ actually present on the system?

no, i have searched this , but didn’t find.

It looks like this is an Ubuntu system, and for this there’s a good site that can help locate software packages, or to see which file(s) a package provides:

For example, here’s a search using the “Search the contents of packages” for the file Ubuntu – Package Contents Search Results --

That can be adjusted for the particular version of Ubuntu running, but shows that the libgl-dev package should provide the file needed, so try

$ sudo apt install -y libgl-dev

There’s good documentation on managing/installing software packages on the main Ubuntu site and wiki:


means this is not the Geant4 installation problem or cmake problem. this is the Ubuntu problem. because when i am doing installation for multi-threading in my laptop , it is working fine but in the lab workstation (that has more processors) it is giving this kind of error. since i want to run my simulation for more number of events.

actually this same problem was occurring at the time of installation of Geant4 but on trying installation 3-4 times , finally it installed. now it is giving the same error for multi-threading.

sure, i can try it tomorrow. and will let you know.


i try this and now i am getting the same error. see attached.

are you by any chance using the build directory of your laptop to build the software for the workstation?

no, not at all.
in workstation , Geant4 is already installed.
in workstation i am trying to make it multi-threading compatible.

in my laptop , i have already multi-threading mode on but it is hanging for 10k primaries in one event so i can’t run this simulation in my laptop.
but when using one primary with 10k events it is working fine in my laptop.

so confused what i should do now. :upside_down_face:

Whilst it’s annoying, I would suggest the best course of action is to delete the existing build directory for Geant4, remove the existing installs of it, and rebuild/install from scratch. It’s unfortunately impossible to diagnose from the above whether this is a build config issue or something amiss on these systems. Completely fresh builds/installs will be able, hopefully, to resolve that if needed.