void fraction_done(double progress,double remaining) { #ifdef USE_MANUAL_CALLSTACK call_stack.enter("fraction_done"); #endif double prog2=1.0-remaining; progress=std::min(progress,1.0); double prog=progress*(1.0-pow(prog2,PROG_POWER))+prog2*pow(prog2,PROG_POWER); boinc_fraction_done(prog); #ifdef USE_MANUAL_CALLSTACK call_stack.exit(); #endif }
static PyObject *boinc_boinc_fraction_done(PyObject *self, PyObject *args) { double fractDone; if (!PyArg_ParseTuple(args, "d", &fractDone)) return NULL; boinc_fraction_done(fractDone); Py_INCREF(Py_None); return Py_None; }
static inline void reportProgress(const AstronomyParameters* ap, const IntegralArea* ia, EvaluationState* es, CALuint step, double dt) { #if BOINC_APPLICATION CALuint prog; prog = es->current_calc_probs + ia->mu_steps * ia->r_steps * step; boinc_fraction_done((double) prog / ap->total_calc_probs); #else printf("Step %u: %fms\n", step, dt); #endif /* BOINC_APPLICATION */ }
static inline void nbodyCheckpoint(const NBodyCtx* ctx, NBodyState* st) { if (nbodyTimeToCheckpoint(ctx, st)) { if (writeCheckpoint(ctx, st)) fail("Failed to write checkpoint\n"); #if BOINC_APPLICATION boinc_checkpoint_completed(); #endif /* BOINC_APPLICATION */ } #if BOINC_APPLICATION boinc_fraction_done(st->tnow / ctx->timeEvolve); #endif /* BOINC_APPLICATION */ }
void fraction_done(double progress,double remaining) { double prog2=1.0-remaining; progress=std::min(progress,1.0); //double prog=progress*(1.0-pow(prog2,PROG_POWER))+prog2*pow(prog2,PROG_POWER); double prog2_6 = prog2*prog2*prog2; prog2_6*=prog2_6; double prog=progress*(1.0-prog2_6)+prog2*prog2_6; if (prog-prev_progress >= 2.0e-5) { boinc_fraction_done(prog); #ifdef PRINT_PROGRESS printf("Progress: %3.3f\r",prog*100.0); fflush(stdout); #endif prev_progress = prog; } }
int main(int argc, char** argv) { int ret_val = boinc_init(); bool ignore_part_file_load = false; CHECK_FOR_FAIL_IN_MAIN(ret_val) //open input file //ret_val = open_input_file(); if (argc != 4) ret_val = BAD_CMD_LINE_PARAMS; CHECK_FOR_FAIL_IN_MAIN(ret_val) max_n = atoi(argv[1]); FAIL_IS_ZERO_IN_MAIN(max_n) k_reg = atoi(argv[2]); FAIL_IS_ZERO_IN_MAIN(k_reg) m = atoi(argv[3]); FAIL_IS_ZERO_IN_MAIN(m) //init p_vals with 0s p_vals = new short[max_n]; b_kvals = new short[max_n]; for (int i = 0; i < max_n; i++) { p_vals[i] = -1; b_kvals[i] = -1; } p_vals[0] = 1; p_vals[1] = 1; b_kvals[0] = 1; /*first check to see if the partition file has been written if it hasn't the checkpoint will have p_vals */ //we just ran finished the part file so no need to load it /*if the part file hasn't been written, the checkpoint will have b_kvals*/ if (!part_file_exists()) { //open checkpoint and load from there if it exists ret_val = open_part_checkpoint(); CHECK_FOR_FAIL_IN_MAIN(ret_val) for (; current_n < max_n; current_n++) { if (boinc_time_to_checkpoint() ) { do_checkpoint(p_vals, current_n); boinc_checkpoint_completed(); } #if _DEBUG && defined(CHECKPOINTS) if (current_n % 100 == 0) do_checkpoint(p_vals, current_n); #endif p(current_n); boinc_fraction_done((double)current_n/((double)max_n *2)); } //write finalresults ret_val = write_part_results(); CHECK_FOR_FAIL_IN_MAIN(ret_val); #if _DEBUG && defined(CHECKPOINTS) for (int i =0; i < 100; i++) { cout << i << " = " << (unsigned int) p_vals[i] << "\r\n"; } #endif //delete old checkpoint file delete_checkpoint(); current_n = 0; ignore_part_file_load = true; }
int main(int argc, char **argv) { int retval; double fd; char output_path[512]; //, chkpt_path[512]; //FILE* state; retval = boinc_init(); if (retval) { fprintf(stderr, "boinc_init returned %d\n", retval); exit(retval); } // extract a --device option std::vector<char*> argVec; int cudaDevice = -1; for(int ii = 0; ii < argc; ii++) { if(cudaDevice < 0 && strcmp(argv[ii], "--device") == 0 && ii + 1 < argc) cudaDevice = atoi(argv[++ii]); else argVec.push_back(argv[ii]); } argc = (int)argVec.size(); argv = &argVec[0]; if(cudaDevice < 0) cudaDevice = 0; boinc_begin_critical_section(); // set the cuda device if ( rcuda::SetCudaDevice(cudaDevice) != 0 ) { fprintf(stderr, "Error setting device %u. Temporary exiting for 60 secs\n", cudaDevice); boinc_temporary_exitHack(); } cudaDeviceProp deviceProp; if(cudaGetDeviceProperties(&deviceProp, cudaDevice) == cudaErrorInvalidDevice) { fprintf(stderr, "Error querying device %u. Temporary exiting for 60 secs\n", cudaDevice); boinc_temporary_exitHack(); } #ifdef WIN32 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); #endif int buffCount = 0x2000; int chainSize = 100; if(deviceProp.major == 1) { /* buffCount = deviceProp.multiProcessorCount * 8;// 8 blocks per multiprocessor buffCount *= deviceProp.maxThreadsPerBlock / 64; // (BLOCK_X_SIZE) // buffCount *= 24; if(deviceProp.minor <= 1) buffCount *= 24; // 24 warps per multiprocessor for compute 1.0 and 1.1 else buffCount *= 32; // 32 warps per multiprocessor for compute 1.2 and 1.3 */ buffCount = 0x2000; } else if(deviceProp.major == 2) { chainSize = 200; /* buffCount = deviceProp.multiProcessorCount * 8;// 8 blocks per multiprocessor buffCount *= deviceProp.maxThreadsPerBlock / 64; //(BLOCK_X_SIZE) buffCount *= 32; // 48 warps per multiprocessor for compute 2.x /* if(deviceProp.minor == 1) { buffCount *= 2; } */ buffCount = 0x4000; } if(cudaDevice > 0) { chainSize = 1000; } if(argc < 10) { fprintf(stderr, "Not enough parameters"); return -1; } std::string sHashRoutineName, sCharsetName, sSalt, sCheckPoints; uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen; uint64 nChainStart; sHashRoutineName = argv[1]; sCharsetName = argv[2]; nPlainLenMin = atoi(argv[3]); nPlainLenMax = atoi(argv[4]); nRainbowTableIndex = atoi(argv[5]); nRainbowChainLen = atoi(argv[6]); nRainbowChainCount = atoi(argv[7]); #ifdef _WIN32 nChainStart = _atoi64(argv[8]); #else nChainStart = atoll(argv[8]); #endif sCheckPoints = argv[9]; std::vector<int> vCPPositions; char *cp = strtok((char *)sCheckPoints.c_str(), ","); while(cp != NULL) { vCPPositions.push_back(atoi(cp)); cp = strtok(NULL, ","); } if(argc == 11) { sSalt = argv[10]; } //std::cout << "Starting ChainGenerator" << std::endl; // Setup CChainWalkContext //std::cout << "ChainGenerator started." << std::endl; if (!CChainWalkContext::SetHashRoutine(sHashRoutineName)) { fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str()); return 1; } //std::cout << "Hash routine validated" << std::endl; if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax)) { std::cerr << "charset " << sCharsetName << " not supported" << std::endl; return 2; } //std::cout << "Plain charset validated" << std::endl; if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex)) { std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl; return 3; } //std::cout << "Rainbowtable index validated" << std::endl; if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall") { // Convert username to unicode const char *szSalt = sSalt.c_str(); int salt_length = strlen(szSalt); unsigned char cur_salt[256]; for (int i=0; i<salt_length; i++) { cur_salt[i*2] = szSalt[i]; cur_salt[i*2+1] = 0x00; } CChainWalkContext::SetSalt(cur_salt, salt_length*2); } else if(sHashRoutineName == "halflmchall") { // The salt is hardcoded into the hash routine // CChainWalkContext::SetSalt((unsigned char*)&salt, 8); } else if(sHashRoutineName == "oracle") { CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length()); } //std::cout << "Opening chain file" << std::endl; // Open file boinc_resolve_filename("result", output_path, sizeof(output_path)); fclose(boinc_fopen(output_path, "a")); FILE *outfile = boinc_fopen(output_path, "r+b"); if (outfile == NULL) { std::cerr << "failed to create " << output_path << std::endl; return 4; } // Check existing chains unsigned int nDataLen = (unsigned int)GetFileLen(outfile); // Round to boundary nDataLen = nDataLen / 10 * 10; if (nDataLen == nRainbowChainCount * 10) { std::cerr << "precomputation of this rainbow table already finished" << std::endl; fclose(outfile); return 0; } fseek(outfile, nDataLen, SEEK_SET); //XXX size_t isn't 32/64 clean size_t nReturn; CChainWalkContext cwc; uint64 nIndex[2]; //time_t tStart = time(NULL); // std::cout << "Starting to generate chains" << std::endl; int maxCalcBuffSize = rcuda::GetChainsBufferSize( buffCount ); std::cerr << "maxCalcBuffSize - estimated: " << buffCount << ". Chosen: " << maxCalcBuffSize << std::endl; uint64 *calcBuff = new uint64[2*maxCalcBuffSize]; int ii; CudaCWCExtender ex(&cwc); rcuda::RCudaTask cuTask; ex.Init(); for(int nCurrentCalculatedChains = nDataLen / 10, calcSize; nCurrentCalculatedChains < nRainbowChainCount; ) { fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount; boinc_fraction_done(fd); cuTask.hash = ex.GetHash(); cuTask.startIdx = nChainStart + nCurrentCalculatedChains; cuTask.idxCount = std::min<int>(nRainbowChainCount - nCurrentCalculatedChains, maxCalcBuffSize); cuTask.dimVec = ex.GetPlainDimVec(); cuTask.dimVecSize = ex.GetPlainDimVecSize()/2; cuTask.charSet = ex.GetCharSet(); cuTask.charSetSize = ex.GetCharSetSize(); cuTask.cpPositions = &vCPPositions[0]; cuTask.cpPosSize = vCPPositions.size(); cuTask.reduceOffset = ex.GetReduceOffset(); cuTask.plainSpaceTotal = ex.GetPlainSpaceTotal(); cuTask.rainbowChainLen = nRainbowChainLen; cuTask.kernChainSize = chainSize; for(ii = 0; ii < cuTask.idxCount; ii++) { calcBuff[2*ii] = cuTask.startIdx + ii; calcBuff[2*ii+1] = 0; } calcSize = rcuda::CalcChainsOnCUDA(&cuTask, calcBuff); BOINC_STATUS boinc_status; boinc_get_status(&boinc_status); if (boinc_status.quit_request || boinc_status.abort_request) { boinc_end_critical_section(); while (1) boinc_sleep(1); } if(calcSize > 0) { nCurrentCalculatedChains += calcSize; for(ii = 0; ii < cuTask.idxCount; ii++) { nIndex[0] = cuTask.startIdx + ii; // nReturn = fwrite(nIndex, 1, 8, outfile); nReturn = fwrite(calcBuff+(2*ii), 1, 8, outfile); nReturn += fwrite(calcBuff+(2*ii+1), 1, 2, outfile); if(nReturn != 10) { std::cerr << "disk write fail" << std::endl; fclose(outfile); return 9; } } } else { std::cerr << "Calculations on CUDA failed!" << std::endl; fclose(outfile); return -1; } } delete [] calcBuff; #ifdef _DEBUG std::cout << "Generation completed" << std::endl; #endif fclose(outfile); boinc_fraction_done(1); boinc_finish(0); }
int main(int argc, char **argv) { int retval; double fd; char output_path[512]; //, chkpt_path[512]; //FILE* state; retval = boinc_init(); if (retval) { fprintf(stderr, "boinc_init returned %d\n", retval); exit(retval); } // get size of input file (used to compute fraction done) // //file_size(input_path, fsize); // See if there's a valid checkpoint file. // If so seek input file and truncate output file // if(argc < 10) { fprintf(stderr, "Not enough parameters"); return -1; } std::string sHashRoutineName, sCharsetName, sSalt, sCheckPoints; uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen; uint64 nChainStart; sHashRoutineName = argv[1]; sCharsetName = argv[2]; nPlainLenMin = atoi(argv[3]); nPlainLenMax = atoi(argv[4]); nRainbowTableIndex = atoi(argv[5]); nRainbowChainLen = atoi(argv[6]); nRainbowChainCount = atoi(argv[7]); #ifdef _WIN32 nChainStart = _atoi64(argv[8]); #else nChainStart = atoll(argv[8]); #endif sCheckPoints = argv[9]; std::vector<uint32> vCPPositions; char *cp = strtok((char *)sCheckPoints.c_str(), ","); while(cp != NULL) { vCPPositions.push_back(atoi(cp)); cp = strtok(NULL, ","); } if(argc == 11) { sSalt = argv[10]; } //std::cout << "Starting ChainGenerator" << std::endl; // Setup CChainWalkContext //std::cout << "ChainGenerator started." << std::endl; if (!CChainWalkContext::SetHashRoutine(sHashRoutineName)) { fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str()); return 1; } //std::cout << "Hash routine validated" << std::endl; if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax)) { std::cerr << "charset " << sCharsetName << " not supported" << std::endl; return 2; } //std::cout << "Plain charset validated" << std::endl; if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex)) { std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl; return 3; } //std::cout << "Rainbowtable index validated" << std::endl; if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall") { // Convert username to unicode const char *szSalt = sSalt.c_str(); int salt_length = strlen(szSalt); unsigned char cur_salt[256]; for (int i=0; i<salt_length; i++) { cur_salt[i*2] = szSalt[i]; cur_salt[i*2+1] = 0x00; } CChainWalkContext::SetSalt(cur_salt, salt_length*2); } else if(sHashRoutineName == "halflmchall") { // The salt is hardcoded into the hash routine // CChainWalkContext::SetSalt((unsigned char*)&salt, 8); } else if(sHashRoutineName == "oracle") { CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length()); } //std::cout << "Opening chain file" << std::endl; // Open file boinc_resolve_filename("result", output_path, sizeof(output_path)); fclose(boinc_fopen(output_path, "a")); FILE *outfile = boinc_fopen(output_path, "r+b"); if (outfile == NULL) { std::cerr << "failed to create " << output_path << std::endl; return 4; } // Check existing chains unsigned int nDataLen = (unsigned int)GetFileLen(outfile); // Round to boundary nDataLen = nDataLen / 10 * 10; if (nDataLen == nRainbowChainCount * 10) { std::cerr << "precomputation of this rainbow table already finished" << std::endl; fclose(outfile); return 0; } nChainStart += (nDataLen / 10); fseek(outfile, nDataLen, SEEK_SET); //XXX size_t isn't 32/64 clean size_t nReturn; CChainWalkContext cwc; uint64 nIndex[2]; //time_t tStart = time(NULL); // std::cout << "Starting to generate chains" << std::endl; for(uint32 nCurrentCalculatedChains = nDataLen / 10; nCurrentCalculatedChains < nRainbowChainCount; nCurrentCalculatedChains++) { uint32 cpcheck = 0; unsigned short checkpoint = 0; fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount; boinc_fraction_done(fd); cwc.SetIndex(nChainStart++); // use a given index now! nIndex[0] = cwc.GetIndex(); for (uint32 nPos = 0; nPos < nRainbowChainLen - 1; nPos++) { // std::cout << "IndexToPlain()" << std::endl; cwc.IndexToPlain(); // std::cout << "PlainToHash()" << std::endl; cwc.PlainToHash(); // std::cout << "HashToIndex()" << std::endl; cwc.HashToIndex(nPos); if(cpcheck < vCPPositions.size() && nPos == vCPPositions[cpcheck]) { checkpoint |= (1 << cpcheck) & (unsigned short)cwc.GetIndex() << cpcheck; cpcheck++; } } //std::cout << "GetIndex()" << std::endl; nIndex[1] = cwc.GetIndex(); // Write chain to disk if ((nReturn = fwrite(&nIndex[1], 1, 8, outfile)) != 8) { std::cerr << "disk write fail" << std::endl; fclose(outfile); return 9; } if((nReturn = fwrite(&checkpoint, 1, 2, outfile)) != 2) { std::cerr << "disk write fail" << std::endl; fclose(outfile); return 9; } } //std::cout << "Generation completed" << std::endl; fclose(outfile); boinc_fraction_done(1); boinc_finish(0); }
void fraction_done(double progress,double remaining) { double prog2=1.0-remaining; progress=std::min(progress,1.0); double prog=progress*(1.0-pow(prog2,PROG_POWER))+prog2*pow(prog2,PROG_POWER); boinc_fraction_done(prog); }
void DC_fractionDone(double fraction) { boinc_fraction_done(fraction); }
void boinc_fraction_done_(double* d) { boinc_fraction_done(*d); }
int main() { int rc = boinc_init(); if (rc) { fprintf(stderr, "APP: boinc_init() failed. rc=%d\n", rc); exit(rc); } srand(time(NULL)); FILE *file_progress; unsigned long long int actual_iteration; int sleep_time; int read_checkpoint; read_checkpoint = checkpoint(&actual_iteration, 0); // Read checkpoint if(read_checkpoint == 1) { actual_iteration = 0; } for(actual_iteration; actual_iteration < ITERATIONS; actual_iteration++) { if (!(file_progress = fopen("progress", "wt"))) { fprintf(stderr,"ERROR: CANNOT OPEN FILE PROGRESS\n"); } else { if(actual_iteration == 0) { fprintf(file_progress, "0"); } else { fprintf(file_progress, "%lf", ((double) actual_iteration / (double) ITERATIONS ) ); } fclose(file_progress); } #if defined(_WIN32) || defined(_WIN64) sleep_time = (rand() % 7) + 1; sleep_time *= 1000; printf("ALX sleep...\n"); Sleep(sleep_time); printf("ALX woke up...\n"); #endif # ifdef __linux__ sleep_time = (rand() % 7) + 1; printf("ALX sleep...\n"); sleep(sleep_time); printf("ALX woke up...\n"); # else sleep_time = (rand() % 7) + 1; printf("ALX sleep...\n"); sleep(sleep_time); printf("ALX woke up...\n"); # endif # ifdef BOINC_VERSION if( boinc_time_to_checkpoint() ) { checkpoint(&actual_iteration, 1); // Save checkpoint boinc_checkpoint_completed(); } # else checkpoint(&actual_iteration, 1); // Save checkpoint # endif boinc_fraction_done( ((double) actual_iteration) / ((double) ITERATIONS) ); } // RESULTS FILE --------------------------------------- FILE *fp; if ((fp=fopen("result", "wt"))==NULL) { printf ("Error: No save result to the file!"); return 1; } fprintf(fp, "1"); fclose (fp); // RESULTS FILE --------------------------------------- boinc_fraction_done(1.0); boinc_finish(0); return 0; }