int main(int argc, const char* argv[]) { int rc; SeparationFlags sf; SeparationPrefs preferences; const char** argvCopy = NULL; #ifdef NDEBUG mwDisableErrorBoxes(); #endif /* NDEBUG */ argvCopy = mwFixArgv(argc, argv); rc = parseParameters(argc, argvCopy ? argvCopy : argv, &sf); if (rc) { if (BOINC_APPLICATION) { freeSeparationFlags(&sf); mwBoincInit(MW_PLAIN); parseParameters(argc, argvCopy, &sf); printVersion(TRUE, FALSE); } mw_printf("Failed to parse parameters\n"); free(argvCopy); mw_finish(EXIT_FAILURE); } rc = separationInit(sf.debugBOINC); free(argvCopy); if (rc) return rc; separationReadPreferences(&preferences); setFlagsFromPreferences(&sf, &preferences, argv[0]); if (sf.processPriority != MW_PRIORITY_INVALID) { mwSetProcessPriority(sf.processPriority); } rc = worker(&sf); freeSeparationFlags(&sf); if (!sf.ignoreCheckpoint && sf.cleanupCheckpoint && rc == 0) { mw_report("Removing checkpoint file '%s'\n", CHECKPOINT_FILE); mw_remove(CHECKPOINT_FILE); } mw_finish(rc); return rc; }
/* Take a program binary from clGetPropramInfo() and a replacement IL source as a string. Replace the .amdil section in the ELF image and return a new copy of the binary. */ unsigned char* getModifiedAMDBinary(unsigned char* bin, size_t binSize, int nStream, MWCALtargetEnum target, size_t* newBinSizeOut) { int fd = -1; int rc = 0; char tmpBinFile[128]; unsigned char* newBin = NULL; if (!bin) return NULL; getTmpBinaryName(tmpBinFile, sizeof(tmpBinFile)); /* Write binary to a temporary file since we need a file descriptor for libelf */ fd = open(tmpBinFile, openMode, openPermMode); if (fd < 0) { mwPerror("Failed to open AMD binary file '%s", tmpBinFile); return NULL; } if (write(fd, bin, binSize) <= 0) { mwPerror("Failed to write temporary binary file '%s'", tmpBinFile); return NULL; } rc = processElf(fd, nStream, target); if (rc == 0) { if (lseek(fd, 0, SEEK_SET) != 0) { mwPerror("Failed to seek temporary binary file '%s'", tmpBinFile); return NULL; } newBin = (unsigned char*) readFD(fd, newBinSizeOut); } if (close(fd) < 0) { mwPerror("Failed to close binary file '%s'", tmpBinFile); free(newBin); return NULL; } mw_remove(tmpBinFile); return newBin; }
int maybeResume(EvaluationState* es) { if (mw_file_exists(resolvedCheckpointPath)) { mw_report("Checkpoint exists. Attempting to resume from it\n"); if (readCheckpoint(es)) { mw_report("Reading checkpoint failed\n"); mw_remove(CHECKPOINT_FILE); return 1; } else mw_report("Successfully resumed checkpoint\n"); } return 0; }
int main(int argc, const char* argv[]) { NBodyFlags nbf = EMPTY_NBODY_FLAGS; int rc = 0; specialSetup(); if (readParameters(argc, argv, &nbf)) exit(EXIT_FAILURE); free(argvCopy); if (nbodyInit(&nbf)) { exit(EXIT_FAILURE); } nbodyPrintVersion(); setDefaultFlags(&nbf); setNumThreads(nbf.numThreads); if (nbf.verifyOnly) { rc = verifyFile(&nbf); } else { rc = runNBodySimulation(&nbf); if (nbf.cleanCheckpoint) { mw_report("Removing checkpoint file '%s'\n", nbf.checkpointFileName); mw_remove(nbf.checkpointFileName); } } freeNBodyFlags(&nbf); mw_finish(rc); return rc; }
int main(int argc, const char* argv[]) { NBodyFlags nbf; int rc = 0; const char** argvCopy = mwFixArgv(argc, argv); nbSpecialSetup(); if (nbReadParameters(argc, argvCopy ? argvCopy : argv, &nbf)) { if (BOINC_APPLICATION) { mwBoincInit(MW_PLAIN); nbReadParameters(argc, argvCopy ? argvCopy : argv, &nbf); nbPrintVersion(TRUE, FALSE); } mw_finish(EXIT_FAILURE); } if (nbInit(&nbf)) { exit(EXIT_FAILURE); } if (BOINC_APPLICATION && mwIsFirstRun()) { nbPrintVersion(TRUE, FALSE); } nbSetDefaultFlags(&nbf); if (nbSetNumThreads(nbf.numThreads)) { mw_finish(EXIT_FAILURE); } if (nbf.verifyOnly) { rc = nbVerifyFile(&nbf); } else if (nbf.matchHistogram) { double emd; emd = nbMatchHistogramFiles(nbf.histogramFileName, nbf.matchHistogram); mw_printf("%.15f\n", emd); rc = isnan(emd); } else { rc = nbMain(&nbf); rc = nbStatusToRC(rc); if (!nbf.noCleanCheckpoint) { mw_report("Removing checkpoint file '%s'\n", nbf.checkpointFileName); mw_remove(nbf.checkpointFileName); } } fflush(stderr); fflush(stdout); /* Odd things happen with the OpenCL one where stdout starts disappearing */ freeNBodyFlags(&nbf); if (BOINC_APPLICATION) { mw_finish(rc); } return rc; }