int LocalExecutor::run(const std::string& binary, const std::map<string, string>& env, const string& dir) const { // create output directory #ifndef DISABLE_ENERGY // set capabilities for energy measurements, required for kernel versions 3.7 and newer // TODO: only do this for newer kernel versions or kernels that have this fix runCommand("sudo setcap cap_sys_rawio=ep " + binary); #endif return runCommand(setupEnv(env) + " IRT_INST_OUTPUT_PATH=" + dir + " " + binary.c_str()); }
void Mediator::handleDispatcher(int index){ int fd = socketManager->getConnectedFD(index); char messageIN[BUFFER_SIZE]; int rd = ioStream->readLine(fd, messageIN, BUFFER_SIZE); if (rd > 0){ cout << "[From Dispatcher...]\t" << messageIN << flush; vector<char*> tokens ; char* token = strtok(messageIN, "|"); while (token != NULL){ tokens.push_back(token); token = strtok(NULL, "|\n"); } if (strcmp(tokens[0],"setupEnv") == 0) setupEnv(tokens, fd); else if (strcmp(tokens[0], "disconnect")==0){ disconnect(tokens[1], fd); } else if (strcmp(tokens[0], "BG_putFile")==0){ BG_put_file(tokens[1], atol(tokens[2]), fd); } else if (strcmp(tokens[0], "BG_start") == 0){ BG_start(tokens[1], atol(tokens[2])); } else if (strcmp(tokens[0], "JOB_STOP") ==0 ){ // processList.stopAll(); // becomeFree(); stopSimulation("dispatcher"); becomeFree(); simulationFinished(); } else if (strcmp(tokens[0], "JOB_ABORT") ==0 ){ abortSimulation(); } else if (strcmp(tokens[0], "getTick\n") == 0){ getTick(fd); } else cout << "else?" << endl << flush; } else{ socketManager->closeByIndex(index); cout << "Dispatcher Closed" << endl << flush; } }
int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition(100, 100); glutInitWindowSize(400, 300); glutCreateWindow("GLUT App"); glutDisplayFunc(onDisplay); glutIdleFunc(onIdle); glutReshapeFunc(onReshape); glutKeyboardUpFunc(onKeyUp); setupEnv(); try { glutMainLoop(); } catch(const std::exception &e) { cout << "exception : " << e.what() << endl; } }
int main( int argc, char* argv[] ) { int i; char screenres[128] = "640x480x24"; char clientcmd[PATH_MAX] = ""; char * cmd = ""; char fontpath[PATH_MAX] = ""; char* args[64] = { "XSDL", port, "-nolock", "-noreset", "-nopn", "-nolisten", "unix", "-fp", fontpath, "-screen", screenres, }; int argnum = 11; char * envp[] = { NULL }; int printHelp = 1; int screenResOverride = 0; int screenButtons = 0; int warnDiskSpaceMb = 0; int builtinKeyboard = 0; int resolutionW = atoi(getenv("DISPLAY_RESOLUTION_WIDTH")); int resolutionH = atoi(getenv("DISPLAY_RESOLUTION_HEIGHT")); int displayW = atoi(getenv("DISPLAY_WIDTH_MM")); int displayH = atoi(getenv("DISPLAY_HEIGHT_MM")); __android_log_print(ANDROID_LOG_INFO, "XSDL", "Actual video resolution %d/%dx%d/%d", resolutionW, displayW, resolutionH, displayH); setupEnv(); SDL_ANDROID_SetScreenKeyboardShown(0); XSDL_initSDL(); while( argc > 1 ) { if( argv[1][0] == ':') { strcpy(port, argv[1]); } else if( strcmp(argv[1], "-nohelp") == 0 ) { printHelp = 0; } else if( strcmp(argv[1], "-screen") == 0 ) { screenResOverride = 1; argc--; argv++; strcpy(screenres, argv[1]); } else if( strcmp(argv[1], "-screenbuttons") == 0 ) { screenButtons = 1; } else if( strcmp(argv[1], "-warndiskspacemb") == 0 && argc > 2 ) { warnDiskSpaceMb = atoi(argv[2]); argc--; argv++; } else { args[argnum] = argv[1]; argnum++; } argc--; argv++; } if (getenv("SDL_RESTART_PARAMS") && getenv("SDL_RESTART_PARAMS")[0]) strcpy(port, getenv("SDL_RESTART_PARAMS")); snprintf(fontpath, sizeof(fontpath), "%s/img/usr/share/fonts/X11/misc," "%s/img/usr/share/fonts/X11/Type1," "%s/img/usr/share/fonts/X11/100dpi," "%s/img/usr/share/fonts/X11/75dpi," "%s/img/usr/share/fonts/X11/cyrillic," "%s/usr/share/fonts", getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR") ); XSDL_unpackFiles(warnDiskSpaceMb); if( !screenResOverride ) { XSDL_showConfigMenu(&resolutionW, &displayW, &resolutionH, &displayH, &builtinKeyboard, &screenButtons); sprintf( screenres, "%d/%dx%d/%dx%d", resolutionW, displayW, resolutionH, displayH, SDL_GetVideoInfo()->vfmt->BitsPerPixel ); } XSDL_generateBackground( port, printHelp, resolutionW, resolutionH ); XSDL_deinitSDL(); if( printHelp ) { sprintf( clientcmd, "%s/usr/bin/xhost + ; %s/usr/bin/xli -onroot -center %s/background.bmp", getenv("SECURE_STORAGE_DIR"), getenv("SECURE_STORAGE_DIR"), getenv("UNSECURE_STORAGE_DIR") ); args[argnum] = "-exec"; args[argnum+1] = clientcmd; argnum += 2; } SDL_ANDROID_SetScreenKeyboardShown( 1 ); if( screenButtons && !SDL_ANDROID_GetScreenKeyboardRedefinedByUser() ) { // Button coords are handled inside xserver/hw/kdrive/sdl/sdl.c SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, 1); } else { SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, 0); SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_1, 0); SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 0); } { char s[16]; sprintf(s, "%d", builtinKeyboard); setenv("XSDL_BUILTIN_KEYBOARD", s, 1); } __android_log_print(ANDROID_LOG_INFO, "XSDL", "XSDL video resolution %s, args:", screenres); for( i = 0; i < argnum; i++ ) __android_log_print(ANDROID_LOG_INFO, "XSDL", "> %s", args[i]); // We should never quit. If that happens, then the server did not start - try with different port number. atexit( &retryLaunchWithDifferentPort ); __android_log_print(ANDROID_LOG_INFO, "XSDL", "XSDL chdir to: %s", getenv("SECURE_STORAGE_DIR")); chdir( getenv("SECURE_STORAGE_DIR") ); // Megahack: change /proc/self/cwd to the X.org data dir, and use /proc/self/cwd path in libX11 android_main( argnum, args, envp ); // Should never exit on success, if we want to terminate we kill ourselves return 0; }
int RemoteExecutor::run(const std::string& binary, const std::map<string, string>& env, const string& dir) const { // extract name of file boost::filesystem::path path = binary; string binaryName = path.filename().string(); // extract directory name string dirName = boost::filesystem::path(dir).filename().string(); boost::uuids::uuid u = uuidGen(); dirName += toString(u); // create ssh-url std::string url = hostname; if (!username.empty()) { url = username + "@" + hostname; } std::string remoteDir = workdir + "/_remote_" + dirName; int res = 0; // start by creating a remote working directory if (res==0) res = runCommand("ssh " + url + " mkdir " + remoteDir); // copy binary if (res==0) res = runCommand("scp -q " + binary + " " + url + ":" + remoteDir); // execute binary switch(system) { case SSH: if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && " + setupEnv(env) + " ./" + binaryName + " && rm " + binaryName + "\""); break; case SGE: if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && qsub -sync yes -b yes -cwd -o std.out -e std.err -pe openmp 1 " + binaryName + "\""); if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && rm " + binaryName + "\""); break; case PBS: assert_fail() << "Not tested!"; if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && qsub -l select=1:ncpus=4:mem=2gb -W block=true -- ./" + binaryName + "\""); if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && rm " + binaryName + "\""); break; case LL: std::string jobscript = "#!/bin/bash\n" "#@ energy_policy_tag=my_energy_tag\n" "#@ max_perf_decrease_allowed=1\n" "#@ wall_clock_limit = 00:05:00\n" "#@ job_name = insieme\n" "#@ job_type = parallel\n" "#@ class = test\n" "#@ node = 1\n" "#@ total_tasks = 1\n" "#@ node_usage = not_shared\n" "#@ initialdir = " + remoteDir + "\n" "#@ output = job$(jobid).out\n" "#@ error = job$(jobid).err\n" "#@ notification=error\n" "#@ [email protected]\n" "#@ restart=no\n" "#@ queue\n" ". /etc/profile\n" ". /etc/profile.d/modules.sh\n" + setupEnv(env); if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && echo \"" + jobscript + "\" | llsubmit -s -\""); //std::cout << "ssh " + url + " \"cd " + remoteDir + " && echo \"" + jobscript + "\" | llsubmit -s -\"\n"; //if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && " + setupEnv(env) + " ./" + binaryName + " && rm " + binaryName + "\""); //if (res==0) res = runCommand("ssh " + url + " \"cd " + remoteDir + " && rm " + binaryName + "\""); break; } // copy back log files if (res==0) res = runCommand("scp -q -r " + url + ":" + remoteDir + " ."); // move files locally if (res==0) res = runCommand("mv -t " + dir + " _remote_" + dirName + "/*"); // delete local files if (res==0) res = runCommand("rm -rf _remote_" + dirName); // delete remote working directory if (res==0) res = runCommand("ssh " + url + " rm -rf " + remoteDir); return res; }