Multithreading on new M1 MacBook and macOS 11.0.1

Multithreading cannot be enabled on the new M1 Macbook and macOS 11.0.1 (Compiler Apple Clang 12.0).

Log:
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:44:53: error:
initializer for thread-local variable must be a constant expression
G4ThreadLocalStatic G4strstreambuf* _instance = new G4strstreambuf();
^~~~~~~~~~~~~~~~~~~~
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:44:41: note:
use ‘thread_local’ to allow this
G4ThreadLocalStatic G4strstreambuf* _instance = new G4strstreambuf();
^
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:50:53: error:
initializer for thread-local variable must be a constant expression
G4ThreadLocalStatic G4strstreambuf* _instance = new G4strstreambuf();
^~~~~~~~~~~~~~~~~~~~
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:50:41: note:
use ‘thread_local’ to allow this
G4ThreadLocalStatic G4strstreambuf* _instance = new G4strstreambuf();
^
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:56:51: error:
initializer for thread-local variable must be a constant expression
…std::ostream* _instance = new std::ostream(_G4coutbuf_p());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:56:39: note:
use ‘thread_local’ to allow this
G4ThreadLocalStatic std::ostream* _instance = new std::ostream(_G4co…
^
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:62:51: error:
initializer for thread-local variable must be a constant expression
…std::ostream* _instance = new std::ostream(_G4cerrbuf_p());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/fermi/dev/geant4/geant4.10.06.p03/source/global/management/src/G4ios.cc:62:39: note:
use ‘thread_local’ to allow this
G4ThreadLocalStatic std::ostream* _instance = new std::ostream(_G4ce…
^

Can you try removing && defined(__x86_64__) from the definitions included in the file:

  • source/global/management/include/tls.hh

and see if that fixes the problem?
Note however that the new Apple Silicon architectures are not yet supported (and won’t be supported in past releases of Geant4).

Awesome! It works now! It’s at least 3 times faster than my 2012 retina MacBook Pro 13’.

A test of the simple gamma detection simulation with QBBC shows M1 Mac is more than 8 times faster than my old MacBook :rofl:

1 Like

It seems like you’re problem got solved, but I’m currently trying to set up Geant4 on a new M1-chipped macbook air; have you been able to get visualizations (via OGL, QT, or otherwise) to work so far? If so, what software are you using to visualize?

Thanks!

I used QT,just make sure you used brew install(for arm64) instead of for x86,then compile through ccmake config,everything is fine.

How’s your examples work? I installed Geant4 on M1 but all the basic examples tell me that its files “building for macos-x86_64 but attempting to link with file built for unknown64”.

How’s your examples, mine doesn’t work.
How did you compiled the files that not coded for arm64.

Did you install all the required libraries through brew? If you do not specify the arch__x86 prefix, then all libraries are installed in the arm64 architecture, including cmake and Qt.

Thanks to your reply, I noticed this and reinstalled Cmake and CLHEP via Homebrew. The compile works fine now but another problem came out:


Now I’m trying to figure out the cause, maybe you can give me some advice.
THANKS again for your kindness and useful advice!!!

Okay, I’m glad to see this. It’s the last step. Just write the environment variables into bash_profile and everything should be done.

Sorry but I’m not so sure about how to add G4ENSDFSTATEDATA environment variable into my bash_profile. I tried the command in the figure you had post, but nothing happened, should I restart after the write?

Write the command into bash_profile just to avoid repeating the above command every time you restart the terminal. If you execute it manually, the Geant4 program can also run correctly.

Make sure you are using bash Shell instead of zsh then use the ‘open ~/.bash_profile’ command and write the above command.After all these are completed, you only need to restart your terminal.

As you can see that I added environmental variable G4ENSDFSTATEDATA into my set, but my exampleB1 still in previous state. Reporting the same warning.

Thank you very much, I have successfully installed Geant4 and ran the exampleB1. Everything works fine and I’m going to write my experience to file and post it on Github. I hope this would help other people stuck like me.

1 Like

Can you share the link if you’ve written a guide about installing Geant4 on M1?