/* called _before_ GAP system initialization to remove command lines, etc. */ void InitPargapmpi( int * argc_ptr, char *** argv_ptr ) { //char * cmd = (*argv_ptr)[0], * tmp; int thrProvided, commSize, myRank; if ( 0 != MPI_Init_thread( argc_ptr, argv_ptr, MPI_THREAD_FUNNELED, &thrProvided ) ) { fputs("ParGAP: panic: couldn't initialize MPI.\n", stderr); SyExit(1); } UNIX_Realtime( (Obj)0 ); /* initialize UNIX_Realtime:time_since_start */ MPI_Comm_size(MPI_COMM_WORLD, &commSize); //if ( INT_INTOBJ( MPIcomm_size( (Obj)0 ) ) <= 1 ) MPI_Comm_rank(MPI_COMM_WORLD, &myRank); if (!myRank) printf("\nGAP started with %d processes\n\n", commSize); //#endif if ( INT_INTOBJ(MPIcomm_rank((Obj)0)) > 0 ) { SyQuiet = ! SyQuiet; { sigset_t fullset; sigfillset( &fullset ); sigdelset( &fullset, SIGINT ); /* Let slaves see interrupts */ //#if 0 //sigprocmask( SIG_BLOCK, &fullset, NULL ); //#endif signal( SIGINT, &ParGAPAnswerIntr ); /* Slaves ignore interrupts */ } } }
/**************************************************************************** ** *F Panic( <msg> ) */ void Panic_(const char * file, int line, const char * fmt, ...) { fprintf(stderr, "Panic in %s:%d: ", file, line); va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end (args); fputs("\n", stderr); SyExit(1); }
void InitSystem ( Int argc, Char * argv [] ) { Char * *ptrlist; UInt i; /* loop variable */ Int res; /* return from option processing function */ /* Initialize global and static variables */ SyCTRD = 1; SyCompilePlease = 0; SyDebugLoading = 0; SyLineEdit = 1; #ifdef HPCGAP SyUseReadline = 0; #else SyUseReadline = 1; #endif SyMsgsFlagBags = 0; SyNrCols = 0; SyNrColsLocked = 0; SyNrRows = 0; SyNrRowsLocked = 0; SyQuiet = 0; SyInitializing = 0; #ifdef SYS_IS_64_BIT SyStorMin = 128 * 1024L; SyStorMax = 2048*1024L; /* This is in kB! */ SyAllocPool = 4096L*1024*1024; /* Note this is in bytes! */ #else SyStorMin = 64 * 1024L; SyStorMax = 1024*1024L; /* This is in kB! */ #ifdef SYS_IS_CYGWIN32 SyAllocPool = 0; /* works better on cygwin */ #else SyAllocPool = 1536L*1024*1024; /* Note this is in bytes! */ #endif #endif SyStorOverrun = 0; SyStorKill = 0; SyUseModule = 1; SyWindow = 0; for (i = 0; i < 2; i++) { UInt j; for (j = 0; j < 7; j++) { SyGasmanNumbers[i][j] = 0; } } preAllocAmount = 4*1024*1024; InitSysFiles(); #ifdef HAVE_LIBREADLINE rl_initialize (); #endif SyInstallAnswerIntr(); #if defined(SYS_DEFAULT_PATHS) SySetGapRootPath( SYS_DEFAULT_PATHS ); #else SySetInitialGapRootPaths(); #endif /* save the original command line for export to GAP */ SyOriginalArgc = argc; SyOriginalArgv = argv; /* scan the command line for options that we have to process in the kernel */ /* we just scan the whole command line looking for the keys for the options we recognise */ /* anything else will presumably be dealt with in the library */ while ( argc > 1 ) { if (argv[1][0] == '-' ) { if ( strlen(argv[1]) != 2 && argv[1][1] != '-') { FPUTS_TO_STDERR("gap: sorry, options must not be grouped '"); FPUTS_TO_STDERR(argv[1]); FPUTS_TO_STDERR("'.\n"); goto usage; } for (i = 0; options[i].shortkey != argv[1][1] && (argv[1][1] != '-' || argv[1][2] == 0 || strcmp(options[i].longkey, argv[1] + 2)) && (options[i].shortkey != 0 || options[i].longkey[0] != 0); i++) ; if (argc < 2 + options[i].minargs) { Char buf[2]; FPUTS_TO_STDERR("gap: option "); FPUTS_TO_STDERR(argv[1]); FPUTS_TO_STDERR(" requires at least "); buf[0] = options[i].minargs + '0'; buf[1] = '\0'; FPUTS_TO_STDERR(buf); FPUTS_TO_STDERR(" arguments\n"); goto usage; } if (options[i].handler) { res = (*options[i].handler)(argv+2, options[i].otherArg); switch (res) { case -1: goto usage; /* case -2: goto fullusage; */ default: ; /* fall through and continue */ } } else res = options[i].minargs; /* recordOption(argv[1][1], res, argv+2); */ argv += 1 + res; argc -= 1 + res; } else { argv++; argc--; } } /* adjust SyUseReadline if no readline support available or for XGAP */ #if !defined(HAVE_LIBREADLINE) SyUseReadline = 0; #endif if (SyWindow) SyUseReadline = 0; /* now that the user has had a chance to give -x and -y, we determine the size of the screen ourselves */ getwindowsize(); /* fix max if it is lower than min */ if ( SyStorMax != 0 && SyStorMax < SyStorMin ) { SyStorMax = SyStorMin; } /* fix pool size if larger than SyStorKill */ if ( SyStorKill != 0 && SyAllocPool != 0 && SyAllocPool > 1024 * SyStorKill ) { SyAllocPool = SyStorKill * 1024; } /* fix pool size if it is given and lower than SyStorMax */ if ( SyAllocPool != 0 && SyAllocPool < SyStorMax * 1024) { SyAllocPool = SyStorMax * 1024; } /* when running in package mode set ctrl-d and line editing */ if ( SyWindow ) { /* SyLineEdit = 1; SyCTRD = 1; */ SyRedirectStderrToStdOut(); syWinPut( 0, "@p", "1." ); } if (SyAllocPool == 0) { /* premalloc stuff */ /* allocate in small chunks, and write something to them * (the GNU clib uses mmap for large chunks and give it back to the * system after free'ing; also it seems that memory is only really * allocated (pagewise) when it is first used) */ ptrlist = (Char **)malloc((1+preAllocAmount/1000)*sizeof(Char*)); for (i = 1; i*1000 < preAllocAmount; i++) { ptrlist[i-1] = (Char *)malloc( 1000 ); if (ptrlist[i-1] != NULL) ptrlist[i-1][900] = 13; } for (i = 1; (i+1)*1000 < preAllocAmount; i++) if (ptrlist[i-1] != NULL) free(ptrlist[i-1]); free(ptrlist); /* ptr = (Char *)malloc( preAllocAmount ); ptr1 = (Char *)malloc(4); if ( ptr != 0 ) free( ptr ); */ } /* should GAP load 'init/lib.g' on initialization */ if ( SyCompilePlease || SyRestoring ) { SyLoadSystemInitFile = 0; } /* the compiler will *not* read in the .gaprc file if ( gaprc && ! ( SyCompilePlease || SyRestoring ) ) { sySetGapRCFile(); } */ #ifdef HAVE_DOTGAPRC /* the users home directory */ if ( getenv("HOME") != 0 ) { strxcpy(DotGapPath, getenv("HOME"), sizeof(DotGapPath)); # if defined(SYS_IS_DARWIN) && SYS_IS_DARWIN /* On Darwin, add .gap to the sys roots, but leave */ /* DotGapPath at $HOME/Library/Preferences/GAP */ strxcat(DotGapPath, "/.gap;", sizeof(DotGapPath)); if (!IgnoreGapRC) { SySetGapRootPath(DotGapPath); } strxcpy(DotGapPath, getenv("HOME"), sizeof(DotGapPath)); strxcat(DotGapPath, "/Library/Preferences/GAP;", sizeof(DotGapPath)); # elif defined(__CYGWIN__) strxcat(DotGapPath, "/_gap;", sizeof(DotGapPath)); # else strxcat(DotGapPath, "/.gap;", sizeof(DotGapPath)); # endif if (!IgnoreGapRC) { SySetGapRootPath(DotGapPath); } DotGapPath[strlen(DotGapPath)-1] = '\0'; /* and in this case we can also expand paths which start with a tilde ~ */ Char userhome[GAP_PATH_MAX]; strxcpy(userhome, getenv("HOME"), sizeof(userhome)); const UInt userhomelen = strlen(userhome); for (i = 0; i < MAX_GAP_DIRS && SyGapRootPaths[i][0]; i++) { const UInt pathlen = strlen(SyGapRootPaths[i]); if (SyGapRootPaths[i][0] == '~' && userhomelen + pathlen < sizeof(SyGapRootPaths[i])) { SyMemmove(SyGapRootPaths[i] + userhomelen, /* don't copy the ~ but the trailing '\0' */ SyGapRootPaths[i] + 1, pathlen); memcpy(SyGapRootPaths[i], userhome, userhomelen); } } } #endif /* now we start */ return; /* print a usage message */ usage: FPUTS_TO_STDERR("usage: gap [OPTIONS] [FILES]\n"); FPUTS_TO_STDERR(" run the Groups, Algorithms and Programming system, Version "); FPUTS_TO_STDERR(SyBuildVersion); FPUTS_TO_STDERR("\n"); FPUTS_TO_STDERR(" use '-h' option to get help.\n"); FPUTS_TO_STDERR("\n"); SyExit( 1 ); }
static Int enableMemCheck(Char ** argv, void * dummy) { SyFputs( "# Error: --enableMemCheck not supported by this copy of GAP\n", 3); SyFputs( " pass --enable-memory-checking to ./configure\n", 3 ); SyExit(2); }