Gromacs  2025-dev-20240614-602a366
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
cmdlineinit.cpp File Reference
#include "gmxpre.h"
#include "cmdlineinit.h"
#include <cstring>
#include <memory>
#include <utility>
#include "gromacs/commandline/cmdlinemodulemanager.h"
#include "gromacs/commandline/cmdlineoptionsmodule.h"
#include "gromacs/commandline/cmdlineprogramcontext.h"
#include "gromacs/utility/basenetwork.h"
#include "gromacs/utility/datafilefinder.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/futil.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/gmxmpi.h"
#include "gromacs/utility/init.h"
#include "gromacs/utility/programcontext.h"
#include "gromacs/utility/smalloc.h"
+ Include dependency graph for cmdlineinit.cpp:


Implements functions from cmdlineinit.h.

Teemu Murtola


void gmx::anonymous_namespace{cmdlineinit.cpp}::broadcastWorld (int size, void *buffer)
 Broadcasts given data from rank zero to all other ranks.
void gmx::anonymous_namespace{cmdlineinit.cpp}::broadcastArguments (int *argc, char ***argv)
 Broadcasts command-line arguments to all ranks. More...
CommandLineProgramContext & gmx::initForCommandLine (int *argc, char ***argv)
 Initializes the GROMACS library for command-line use. More...
void gmx::finalizeForCommandLine ()
 Deinitializes the GROMACS library after initForCommandLine(). More...
int gmx::processExceptionAtExitForCommandLine (const std::exception &ex)
 Handles an exception and deinitializes after initForCommandLine. More...
int gmx::runCommandLineModule (int argc, char *argv[], ICommandLineModule *module)
 Implements a main() method that runs a single module. More...
int gmx::runCommandLineModule (int argc, char *argv[], const char *name, const char *description, std::function< std::unique_ptr< ICommandLineOptionsModule >()> factory)
 Implements a main() method that runs a single module. More...
int gmx_run_cmain (int argc, char *argv[], int(*mainFunction)(int, char *[]))
 Implements a main() method that runs a given C main function. More...


< CommandLineProgramContext > 
 Global context instance initialized in initForCommandLine().
std::unique_ptr< DataFileFinder > gmx::anonymous_namespace{cmdlineinit.cpp}::g_libFileFinder
 Global library data file finder that respects GMXLIB.

Function Documentation

int gmx_run_cmain ( int  argc,
char *  argv[],
int(*)(int, char *[])  mainFunction 

Implements a main() method that runs a given C main function.

argcargc passed to main().
argvargv passed to main().
mainFunctionThe main()-like method to wrap.

This method creates a dummy command line module that does its processing by calling mainFunction. It then runs this module as with gmx::runCommandLineModule(). This allows the resulting executable to handle common options and do other common actions (e.g., startup headers) without duplicate code in the main methods.

mainFunction should call parse_common_args() to process its command-line arguments.


int my_main(int argc, char *argv[])
// <...>
int main(int argc, char *argv[])
return gmx_run_cmain(argc, argv, &my_main);

Does not throw. All exceptions are caught and handled internally.