Micro file executed before the program starts

Hello all,
I am trying to run my application with the source defined by a micro file. So, when I start my file with, for instance, “./task macros/gps.mac” the program executes the gps.mac file before the environment is set up. so I get this error. “COMMAND NOT FOUND </gps/particle e->”. I also have tried “./task -i macros/gps.mac” but it doesn’t excute the mac file.
I don’t get this error on my personal laptop. but when I try to run my code on our university cluster, I face this problem.
I appreciate any suggestions.

Can you post your main() program please? Have you confirmed that the program on the cluster was compiled with the same code as on the laptop?

1 Like

This is my main. I use Geant4.10.05.p01 on my laptop, and the cluster has Geant4-10.04.p02 which I don’t know how they installed it.

#include

// (single- or multi-threaded depending on the condition)
#ifdef G4MULTITHREADED
#include <G4MTRunManager.hh>
using RunManager = G4MTRunManager;
#else
#include <G4RunManager.hh>
using RunManager = G4RunManager;
#endif

#ifdef G4VIS_USE
#include <G4VisExecutive.hh>
#endif

#ifdef G4UI_USE
#include <G4UIExecutive.hh>
#endif

#include <G4String.hh>
#include <G4UImanager.hh>

#include “ActionInitialization.hh”

#include “DetectorConstruction.hh”
#include “PhysicsList.hh”

using namespace std;

int main(int argc, char** argv)
{
std::cout << “Application starting…” << std::endl;

vector<G4String> macros;
bool interactive = false;

// Parse command line arguments
if  (argc == 1)
{
    interactive = true;
}
else
{
    for (int i = 1; i < argc; i++)
    {
        G4String arg = argv[i];
        if (arg == "-i" || arg == "--interactive")
        {
            interactive = true;
            continue;
        }
        else
        {
            macros.push_back(arg);
        }
    }
}

// Create the run manager (MT or non-MT) and make it a bit verbose.
auto runManager = new RunManager();
runManager->SetVerboseLevel(1);

#ifdef G4VIS_USE
    G4VisManager* visManager = new G4VisExecutive();
    visManager->Initialize();
#endif


runManager->SetUserInitialization(new PhysicsList());

runManager->SetUserInitialization(new DetectorConstruction());
runManager->SetUserInitialization(new ActionInitialization());

#ifdef G4UI_USE
    G4UIExecutive* ui = nullptr;
    if (interactive)
    {
        ui = new G4UIExecutive(argc, argv);
    }
#endif

G4UImanager* UImanager = G4UImanager::GetUIpointer();


for (auto macro : macros)
{
    G4String command = "/control/execute ";
    UImanager->ApplyCommand(command + macro);
}

#ifdef G4UI_USE
    if (interactive)
    {
        if (ui->IsGUI()) 
        { 
            UImanager->ApplyCommand("/control/execute macros/ui.mac"); 
        } 
        else 
        { 
            UImanager->ApplyCommand("/run/initialize"); 
        } 
        ui->SessionStart();
        delete ui;
    }
#endif

delete runManager;

return 0;

}

When you tried it on your laptop, have you executed your program exactly the same way as you did for the cluster, or you run it in interactive mode and executed the macro interactively?
/gps/ UI commands should be available only after RunManager is initialized, and /run/initialize command in your main() is applied only for interactive mode.
Adding /run/initialize into your gps.mac before the first appearance of /gps/ command may fix the issue.

2 Likes

Thank you for your hints. It actually worked. But I faced a new problem. My results for the same code and the same source are different on my laptop and the cluster. The version of Geant4 on my laptop and the cluster are different. Could that be the reason or I have a mistake in some part of my code?

Yes. If you use different Geant4 versions, there can be differences (large or subtle), in the physics processes, or cross-section tables, etc. Each release comes with very detailed Release Notes that describe the changes from the previous version.

If the random number sequence changes for any reason, then everything after that will be slightly different (statistically equivalent, but not identical).

2 Likes

Thank you for your insightful answer. I really appreciate it.