int getDependencies(nfs_sparse_mat_t *M, llist_t *C, s32 *deps, s32 origC, long testMode) /***************************************************/ { double blstart, blstop, difficulty; int res; s32 i, j; u64 *tmpDeps; difficulty = (M->numCols/64.0)*(M->cIndex[M->numCols] + M->numCols*M->numDenseBlocks); difficulty /= 1000000.0; printf("Matrix difficulty is about %1.2lf\n", difficulty); if (!testMode) printf("Doing block Lanczos...\n"); blstart = sTime(); tmpDeps = (u64 *)malloc(M->numCols*sizeof(u64)); res = blockLanczos64(tmpDeps, MultB64, MultB_T64, (void *)M, M->numCols, testMode); blstop = sTime(); printf("Returned %d. Block Lanczos took %1.2lf seconds.\n", res, blstop-blstart); msgLog("", "BLanczosTime: %1.1lf", blstop-blstart); if (res < 0) return res; /******************************************************/ /* Now, we need to translate the dependencies back to */ /* deps for the original matrix. */ /******************************************************/ memset(deps, 0x00, origC*sizeof(s32)); for (i=0; i<M->numCols; i++) { for (j=C->index[i]; j<C->index[i+1]; j++) deps[C->data[j]] ^= (s32)(tmpDeps[i]&0xFFFFFFFF); } free(tmpDeps); return 0; }
void StatisticsDock::updateStatistics() { lastUpdateLabel->setText(QDateTime::currentDateTime().toString("hh:mm:ss")); int iElapsedTime = elapsedTime->elapsed(); QString sTime(""); sTime.sprintf("%2.2d:%2.2d:%2.2ds", iElapsedTime / 3600, iElapsedTime/60 - ((iElapsedTime / 3600) * 60), iElapsedTime % 60); appRunningTimeLabel->setText(sTime); }
Stream& BugLog() { if(snobuglog) return NilStream(); static LogStream *s; if(!s) { INTERLOCKED if(!s) { static byte lb[sizeof(LogStream)]; s = new(lb) LogStream; char h[200]; sTime(h, ".buglog"); s->Create(h, false); } }
void KeyDispose() { //翻盖处理跟检测 if(BoxOpenCheck()) return ; //USB状态检测 //USbInCheck() ; // USB信息处理 UsbInfoDispose(); // 按键信息处理 KeyInfoDispose(); //定时器锁定信息 #ifdef DS1307_ON if(System.Sys.PassWrd.InputErrCount >= INPUT_ERR_TIME_MAX) { uint32_t m ; GR_DBG_PRINTF("System.Sys.PassWrd.InputErrCount: %d \n\n ",System.Sys.PassWrd.InputErrCount); GR_DBG_PRINTF("System.Sys.PassWrd.LockTime: %d \n\n ",System.Sys.PassWrd.LockTime); DS1307_RD(&date[0]); m = sTime(NowTime); GR_DBG_PRINTF("sTime(NowTime): %d \n\n",m); m = m - System.Sys.PassWrd.LockTime; GR_DBG_PRINTF("locked time is gone: %d \n\n",m); if ( m >= SYS_LOCK_TIME_SETTING ) //锁定时间2分钟 { System.Sys.PassWrd.InputErrCount = 0 ; System.Sys.SaveInfoFlag = 0x01 ; } } #else if(System.Sys.PassWrd.InputErrCount >= INPUT_ERR_TIME_MAX) { System.Sys.PassWrd.InputErrCount = 0 ; System.Sys.SaveInfoFlag = 0x01 ; } #endif // 系统保存信息 if(System.Sys.SaveInfoFlag == 0x01) { SystemWriteBCKData(); } // 系统软硬件错误 SYS_Error(); }
void OPMisc::initialise() { double kt = Sim->dynamics.getLiouvillean().getkT(); dout << "Particle Count " << Sim->N << "\nSim Unit Length " << Sim->dynamics.units().unitLength() << "\nSim Unit Time " << Sim->dynamics.units().unitTime() << "\nDensity " << Sim->dynamics.getNumberDensity() * Sim->dynamics.units().unitVolume() << "\nPacking Fraction " << Sim->dynamics.getPackingFraction() << "\nSim Temperature " << kt << "\nReduced Temperature " << kt / Sim->dynamics.units().unitEnergy() << std::endl; dout << "No. of Species " << Sim->dynamics.getSpecies().size() << "\nSimulation box length <x y z> < "; for (size_t iDim = 0; iDim < NDIM; iDim++) dout << Sim->primaryCellSize[iDim]/Sim->dynamics.units().unitLength() << " "; dout << ">" << std::endl; Vector sumMV (0,0,0); //Determine the discrepancy VECTOR BOOST_FOREACH( const Particle & Part, Sim->particleList) { Vector pos(Part.getPosition()), vel(Part.getVelocity()); Sim->dynamics.BCs().applyBC(pos, vel); sumMV += vel * Sim->dynamics.getSpecies(Part).getMass(Part.getID()); } dout << "Total momentum <x,y,z> <"; for (size_t iDim = 0; iDim < NDIM; iDim++) dout << sumMV[iDim] / Sim->dynamics.units().unitMomentum() << " "; dout << ">" << std::endl; std::time(&tstartTime); clock_gettime(CLOCK_MONOTONIC, &acc_tstartTime); std::string sTime(std::ctime(&tstartTime)); sTime[sTime.size()-1] = ' '; dout << "Started on " << sTime << std::endl; }
BOOL CTimeHelper::DecodeOffset(LPCTSTR szTime, double& dAmount, int& nUnits, BOOL bMustHaveSign) { // sanity checks CString sTime(szTime); Misc::Trim(sTime); if (sTime.IsEmpty()) return FALSE; // Sign defaults to +ve int nSign = 1; TCHAR nFirst = Misc::First(sTime); switch (nFirst) { case '+': nSign = 1; Misc::TrimFirst(sTime); break; case '-': nSign = -1; Misc::TrimFirst(sTime); break; default: // Must have sign or be number if (bMustHaveSign || ((nFirst < '0') || (nFirst > '9'))) return FALSE; } // Trailing units TCHAR nLast = Misc::Last(sTime); if (IsValidUnit(nLast)) nUnits = nLast; else nUnits = THU_HOURS; // Rest is number (note: ttof ignores any trailing letters) dAmount = (nSign * _ttof(sTime)); return TRUE; }
void ScreenStatsOverlay::UpdateSkips() { /* Use our own timer, so we ignore `/tab. */ const float UpdateTime = m_timerSkip.GetDeltaTime(); /* FPS is 0 for a little while after we load a screen; don't report * during this time. Do clear the timer, though, so we don't report * a big "skip" after this period passes. */ if( !DISPLAY->GetFPS() ) return; /* We want to display skips. We expect to get updates of about 1.0/FPS ms. */ const float ExpectedUpdate = 1.0f / DISPLAY->GetFPS(); /* These are thresholds for severity of skips. The smallest * is slightly above expected, to tolerate normal jitter. */ const float Thresholds[] = { ExpectedUpdate * 2.0f, ExpectedUpdate * 4.0f, 0.1f, -1 }; int skip = 0; while( Thresholds[skip] != -1 && UpdateTime > Thresholds[skip] ) skip++; if( skip ) { RString sTime( SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast()) ); static const RageColor colors[] = { RageColor(0,0,0,0), /* unused */ RageColor(1.0f,1.0f,1.0f,1), /* white*/ RageColor(1.0f,1.0f,0.0f,1), /* yellow */ RageColor(1.0f,0.4f,0.4f,1) /* light red */ }; AddTimestampLine( ssprintf("%s: %.0fms (%.0f)", sTime.c_str(), 1000*UpdateTime, UpdateTime/ExpectedUpdate), colors[skip] ); if( PREFSMAN->m_bLogSkips ) LOG->Trace( "Frame skip: %.0fms (%.0f)", 1000*UpdateTime, UpdateTime/ExpectedUpdate ); } }
int main(int argC, char *args[]) /****************************************************/ { char fbName[64], prelName[40], newRelName[64], depName[64], colName[64]; char str[128], line[128]; int i, qcbSize = DEFAULT_QCB_SIZE, seed=DEFAULT_SEED, retVal=0; u32 maxRelsInFF=MAX_RELS_IN_FF; double startTime, stopTime; s32 totalRels, relsInFile; nfs_fb_t FB; multi_file_t prelF, lpF; FILE *fp; lxmalloc(4000000,0); prelF.numFiles = DEFAULT_NUM_FILES; lpF.numFiles = 0; prelF.prefix[0] = lpF.prefix[0]=0; fbName[0] = newRelName[0] = 0; strcpy(depName, DEFAULT_DEPNAME); strcpy(colName, DEFAULT_COLNAME); strcpy(lpF.prefix, DEFAULT_LPI_NAME); strcpy(prelF.prefix, DEFAULT_PRELPREFIX); line[0]=0; printf(START_MSG, GGNFS_VERSION); minFF=0; for (i=1; i<argC; i++) { if (strcmp(args[i], "-fb")==0) { if ((++i) < argC) strncpy(fbName, args[i], 64); } else if (strcmp(args[i], "-cols")==0) { if ((++i) < argC) strncpy(colName, args[i], 64); } else if (strcmp(args[i], "-prel")==0) { if ((++i) < argC) strncpy(prelF.prefix, args[i], 32); } else if (strcmp(args[i], "-qs")==0) { if ((++i) < argC) qcbSize = atoi(args[i]); } else if (strcmp(args[i], "-minff")==0) { if ((++i) < argC) minFF = atoi(args[i]); } else if (strcmp(args[i], "-seed")==0) { if ((++i) < argC) seed = atoi(args[i]); } else if (strcmp(args[i], "-v")==0) { verbose++; } else if (strcmp(args[i], "-maxrelsinff")==0) { if ((++i) < argC) maxRelsInFF = atoi(args[i]); } } maxRelsInFF=MIN(MAX_RELS_IN_FF,maxRelsInFF); srand(seed); startTime = sTime(); if ((fbName[0]==0) || (prelF.prefix[0]==0)) { printf("USAGE: %s %s\n", args[0], USAGE); exit(0); } msgLog("", "GGNFS-%s : matbuild", GGNFS_VERSION); sprintf(prelName, "%s.%d", prelF.prefix, 0); initFB(&FB); if (loadFB(fbName, &FB)) { printf("Could not load FB from %s!\n", fbName); exit(-1); } if (minFF < FB.rfb_size + FB.afb_size + 64 + 32) minFF = FB.rfb_size + FB.afb_size + 64 + 32; if (verbose) printf("Getting QCB of size %d...\n", qcbSize); /* Very strange! Why is this being done here?? */ generateQCB(&FB, qcbSize); count_prelF(&prelF); totalRels=0; for (i=0; i<prelF.numFiles; i++) { sprintf(prelName, "%s.%d", prelF.prefix, i); if ((fp = fopen(prelName, "rb"))) { rewind(fp); fread(&relsInFile, sizeof(s32), 1, fp); fclose(fp); } totalRels += relsInFile; } finalFF = getCols(colName, &prelF, &lpF, &FB, minFF, maxRelsInFF); msgLog("", "Heap stats for matbuild run."); logHeapStats(); if (finalFF > 0) msgLog("", "rels:%" PRId32 ", initialFF:%" PRId32 ", finalFF:%" PRId32, initialRelations, initialFF, finalFF); if (finalFF < minFF) { printf("More columns needed (current = %" PRId32 ", min = %" PRId32 ")\n", finalFF, minFF); exit(0); } /* Write some header information that will eventually be needed in the `deps' file. */ if (!(fp = fopen("depinf", "wb"))) { fprintf(stderr, "Error opening %s for write!\n", "depinf"); } else { sprintf(str, "NUMCOLS: %8.8" PRIx32, finalFF); writeBinField(fp, str); sprintf(str, "COLNAME: %s.index", colName); writeBinField(fp, str); sprintf(str, "MAXRELS: %8.8" PRIx32, totalRels); writeBinField(fp, str); sprintf(str, "RELPREFIX: %s", prelF.prefix); writeBinField(fp, str); sprintf(str, "RELFILES: %x", prelF.numFiles); writeBinField(fp, str); sprintf(str, "LPFPREFIX: %s", lpF.prefix); writeBinField(fp, str); sprintf(str, "LPFFILES: %x", lpF.numFiles); writeBinField(fp, str); sprintf(str, "END_HEADER"); writeBinField(fp, str); fclose(fp); } printf("`depinf' written. You can now run matprune.\n"); msgLog("", "depinf file written. Run matprune."); stopTime = sTime(); printf("Total elapsed time: %1.2lf seconds.\n", stopTime-startTime); return retVal; }
void OPMisc::output(magnet::xml::XmlStream &XML) { std::time_t tendTime; time(&tendTime); std::string sTime(std::ctime(&tstartTime)); //A hack to remove the newline character at the end sTime[sTime.size()-1] = ' '; std::string eTime(std::ctime(&tendTime)); //A hack to remove the newline character at the end eTime[eTime.size()-1] = ' '; timespec acc_tendTime; clock_gettime(CLOCK_MONOTONIC, &acc_tendTime); double duration = double(acc_tendTime.tv_sec) - double(acc_tstartTime.tv_sec) + 1e-9 * (double(acc_tendTime.tv_nsec) - double(acc_tstartTime.tv_nsec)); double collpersec = static_cast<double>(Sim->eventCount) / duration; dout << "Ended on " << eTime << "\nTotal Collisions Executed " << Sim->eventCount << "\nAvg Coll/s " << collpersec << "\nSim time per second " << Sim->dSysTime / (Sim->dynamics.units().unitTime() * duration) << std::endl; XML << magnet::xml::tag("Misc") << magnet::xml::tag("Memusage") << magnet::xml::attr("MaxKiloBytes") << magnet::process_mem_usage() << magnet::xml::endtag("Memusage") << magnet::xml::tag("Density") << magnet::xml::attr("val") << Sim->dynamics.getNumberDensity() * Sim->dynamics.units().unitVolume() << magnet::xml::endtag("Density") << magnet::xml::tag("PackingFraction") << magnet::xml::attr("val") << Sim->dynamics.getPackingFraction() << magnet::xml::endtag("PackingFraction") << magnet::xml::tag("SpeciesCount") << magnet::xml::attr("val") << Sim->dynamics.getSpecies().size() << magnet::xml::endtag("SpeciesCount") << magnet::xml::tag("ParticleCount") << magnet::xml::attr("val") << Sim->N << magnet::xml::endtag("ParticleCount") << magnet::xml::tag("SimLength") << magnet::xml::attr("Collisions") << Sim->eventCount << magnet::xml::attr("OneParticleEvents") << singleEvents << magnet::xml::attr("TwoParticleEvents") << dualEvents << magnet::xml::attr("Time") << Sim->dSysTime / Sim->dynamics.units().unitTime() << magnet::xml::endtag("SimLength") << magnet::xml::tag("Timing") << magnet::xml::tag("Start") << magnet::xml::attr("val") << sTime << magnet::xml::endtag("Start") << magnet::xml::tag("End") << magnet::xml::attr("val") << eTime << magnet::xml::endtag("End") << magnet::xml::tag("Duration") << magnet::xml::attr("val") << duration << magnet::xml::endtag("Duration") << magnet::xml::tag("CollPerSec") << magnet::xml::attr("val") << collpersec << magnet::xml::attr("CondorWarning") << std::string("true") << magnet::xml::endtag("CollPerSec") << magnet::xml::endtag("Timing") << magnet::xml::tag("SystemBoxLength") << magnet::xml::attr("val") << 1.0/Sim->dynamics.units().unitLength(); char name[2] = "x"; for (size_t iDim = 0; iDim < NDIM; iDim++) { name[0] = 'x' + iDim; XML << magnet::xml::tag(name) << magnet::xml::attr("val") << Sim->primaryCellSize[iDim]/Sim->dynamics.units().unitLength() << magnet::xml::endtag(name); } XML << magnet::xml::endtag("SystemBoxLength"); Vector sumMV(0, 0, 0); //Determine the discrepancy VECTOR BOOST_FOREACH( const Particle & Part, Sim->particleList) sumMV += Part.getVelocity() * Sim->dynamics.getSpecies(Part).getMass(Part.getID()); XML << magnet::xml::tag("Total_momentum") << sumMV / Sim->dynamics.units().unitMomentum() << magnet::xml::endtag("Total_momentum") << magnet::xml::tag("totMeanFreeTime") << magnet::xml::attr("val") << getMFT() << magnet::xml::endtag("totMeanFreeTime"); XML << magnet::xml::tag("MemoryUsage") << magnet::xml::attr("ResidentSet") << magnet::process_mem_usage() << magnet::xml::endtag("MemoryUsage") << magnet::xml::endtag("Misc"); }
void dec_viterbi_F(dvector* Metr_mem, unsigned char* history_mem, bitvector* bit_stream, const dvarray* Dist, const param_viterbi_t* param, size_t n) { size_t i_in = 0, i_punct, i, j, vote, bv = 0; double *Metr0, *Metr1, *Metr; char X0, X1, Y0, Y1; unsigned char history[MAX_Nways][MAX_history]; unsigned char history_new[MAX_Nways][MAX_history+1]; #if 0 /* FIXME */ /* Time varies between runs giving false negatives about which run (JIT, CBE, or LLC) failed */ double startTime, now, estTotal; #endif /* 0 */ if (bit_stream->length) { bitvector_clear(bit_stream); } if (n==0) { n = Dist->data[0].length; } bitvector_init(bit_stream, n); Metr = (double*)malloc(Metr_mem->length*sizeof(double)); Metr0 = (double*)malloc(Metr_mem->length*sizeof(double)); Metr1 = (double*)malloc(Metr_mem->length*sizeof(double)); memcpy(Metr, Metr_mem->data, Metr_mem->length*sizeof(double)); memcpy(history, history_mem, sizeof(history)); #if 0 /* FIXME */ /* Time varies between runs giving false negatives about which run (JIT, CBE, or LLC) failed */ startTime = sTime(); #endif /* 0 */ i_punct = 0; while (i_in<bit_stream->length) { #if 0 /* FIXME */ /* Time varies between runs giving false negatives about which run (JIT, CBE, or LLC) failed */ if (i_in && (i_in % 10000 == 0)) { now = sTime(); estTotal = ((double)1.02*bit_stream->length/((double)i_in))*(now-startTime); printf("Viterbi: Estimate %1.1lf%% complete (%1.1lf seconds / %1.1lf seconds)...\n", (double)100.0*i_in/(1.02*bit_stream->length), now-startTime, estTotal); fflush(stdout); } #endif /* 0 */ memcpy(Metr0, Metr, Metr_mem->length*sizeof(double)); memcpy(Metr1, Metr, Metr_mem->length*sizeof(double)); if (param->punct1[i_punct] == 1) { for (i=0; i<param->Nways; ++i) { X0 = param->Tabl_X[i]; X1 = 1 - param->Tabl_X[i]; Metr0[i] = Metr0[i] + Dist->data[X0].data[i_in]; Metr1[i] = Metr1[i] + Dist->data[X1].data[i_in]; } ++i_in; } if (param->punct2[i_punct] == 1) { if (i_in >= bit_stream->length) { assert(0 && "Synchronization in Viterbi: i_in > size(Dist,2)"); } for (i=0; i<param->Nways; ++i) { Y0 = param->Tabl_Y[i]; Y1 = 1 - param->Tabl_Y[i]; Metr0[i] = Metr0[i] + Dist->data[Y0].data[i_in]; Metr1[i] = Metr1[i] + Dist->data[Y1].data[i_in]; } ++i_in; } for (i=0; i<param->Nways/2; ++i) { if (Metr0[2*i] <= Metr0[2*i+1]) { Metr[i] = Metr0[2*i]; history_new[i][0] = 0; for (j=0; j<MAX_history; ++j) { history_new[i][j+1] = history[2*i][j]; } } else { Metr[i] = Metr0[2*i+1]; history_new[i][0] = 1; for (j=0; j<MAX_history; ++j) { history_new[i][j+1] = history[2*i+1][j]; } } if (Metr1[2*i] <= Metr1[2*i+1]) { Metr[i+param->Nways/2] = Metr1[2*i]; history_new[i+param->Nways/2][0] = 0; for (j=0; j<MAX_history; ++j) { history_new[i+param->Nways/2][j+1] = history[2*i][j]; } } else { Metr[i+param->Nways/2] = Metr1[2*i+1]; history_new[i+param->Nways/2][0] = 1; for (j=0; j<MAX_history; ++j) { history_new[i+param->Nways/2][j+1] = history[2*i+1][j]; } } } for (vote=i=0; i<param->Nways; ++i) { vote += (history_new[i][MAX_history] == 0); } if (vote >= param->Nways/2) { bit_stream->data[bv++] = 0; } else { bit_stream->data[bv++] = 1; } for (i=0; i<param->Nways; ++i) { for (j=0; j<MAX_history; ++j) { history[i][j] = history_new[i][j]; } } if (++i_punct == param->n_in) { i_punct = 0; } } bit_stream->data = (unsigned char*)realloc(bit_stream->data, bv*sizeof(unsigned char)); bit_stream->length = bv; memcpy(Metr_mem->data, Metr, Metr_mem->length*sizeof(double)); memcpy(history_mem, history, sizeof(history)); free(Metr); free(Metr0); free(Metr1); }
int main(int argC, char *args[]) /****************************************************/ { char colName[64], depName[64], str[1024]; double startTime, stopTime; s32 *deps, origC; u32 seed=DEFAULT_SEED; long testMode=0; struct stat fileInfo; nfs_sparse_mat_t M; llist_t C; int i; FILE *fp, *ifp; strcpy(colName, DEFAULT_COLNAME); strcpy(depName, DEFAULT_DEPNAME); printf(START_MSG, GGNFS_VERSION); seed=time(0); /* This probably shouldn't be needed, but whatever. */ seed = ((seed % 1001)*seed) ^ (171*seed); for (i=1; i<argC; i++) { if (strcmp(args[i], "-v")==0) { verbose++; } else if (strcmp(args[i], "-seed")==0) { if ((++i) < argC) { seed = atol(args[i]); } } else if (strcmp(args[i], "-save")==0) { if ((++i) < argC) { matsave_interval = 60 * atoi(args[i]); } } else if (strcmp(args[i], "-test")==0) { testMode = 1; } else if (strcmp(args[i], "--help")==0) { printf("USAGE: %s %s\n", args[0], USAGE); exit(0); } } srand(seed); if (stat("depinf", &fileInfo)) { printf("Could not stat depinf! Are you trying to run %s to soon?\n", args[0]); return -1; } seedBlockLanczos(seed); startTime = sTime(); msgLog("", "GGNFS-%s : matsolve (seed=%" PRIu32 ")", GGNFS_VERSION, seed); printf("Using PRNG seed=%" PRIu32 ".\n", seed); readSparseMat(&M, "spmat"); ll_read(&C, "sp-index"); printf("Verifying column map..."); fflush(stdout); ll_verify(&C); printf("done.\n"); printf("Matrix loaded: it is %" PRId32 " x %" PRId32 ".\n", M.numRows, M.numCols); if (M.numCols < (M.numRows + 64)) { printf("More columns needed (current = %" PRId32 ", min = %" PRId32 ")\n", M.numCols, M.numRows+64); free(M.cEntry); free(M.cIndex); exit(-1); } if (checkMat(&M, delCols, &numDel)) { printf("checkMat() returned some error! Terminating...\n"); exit(-1); } /* We need to know how many columns there were in the original, unpruned matrix, so we know how much memory to allocate for the dependencies. */ if (!(ifp = fopen("depinf", "rb"))) { fprintf(stderr, "Error opening depinf for read!\n"); exit(-1); } readBinField(str, 1024, ifp); while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) { if (strncmp(str, "NUMCOLS: ", 9)==0) { sscanf(&str[9], "%" SCNx32, &origC); } readBinField(str, 1024, ifp); } fclose(ifp); printf("Original matrix had %" PRId32 " columns.\n", origC); if (!(deps = (s32 *)malloc(origC*sizeof(s32)))) { printf("Could not allocate %" PRIu32 " bytes for the dependencies.\n", (u32)(origC*sizeof(s32)) ); free(M.cEntry); free(M.cIndex); return -1; } if (getDependencies(&M, &C, deps, origC, testMode) == 0) { if (!(ifp = fopen("depinf", "rb"))) { fprintf(stderr, "Error opening depinf for read!\n"); exit(-1); } printf("Writing dependencies to file %s.\n", depName); if (!(fp = fopen(depName, "wb"))) { fprintf(stderr, "Error opening %s for write!\n", depName); fclose(ifp); } else { /* Get the header information from depinf. */ readBinField(str, 1024, ifp); while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) { writeBinField(fp, str); readBinField(str,1024,ifp); } if (strncmp(str, "END_HEADER",10)) { fprintf(stderr, "Error: depinf is corrupt!\n"); fclose(ifp); fclose(fp); exit(-1); } writeBinField(fp, str); fclose(ifp); fwrite(deps, sizeof(s32), origC, fp); fclose(fp); } } stopTime = sTime(); printf("Total elapsed time: %1.2lf seconds.\n", stopTime-startTime); msgLog("", "Heap stats for matsolve run:"); logHeapStats(); free(M.cEntry); free(M.cIndex); free(deps); return 0; }
static void master(void) /********************************************************************/ /* One of the MPI processes will be distinguished as a master node. */ /* That master node will call this function only, so this is the */ /* function that controls all the slave nodes. */ /********************************************************************/ { node_t nodeList[MAX_NODES]; int numNodes, j, numSlaves, numOnCall; long colsPerNode, c0, c1; nfs_sparse_mat_t M; double blstart, blstop; long *deps; /* Load the matrix. */ /* This is not yet done, as it could be a bit tricky. It might not fit into RAM on a single node, which means we should really preprocess it first on a machine with plenty of RAM, save the preprocessed version to disk, and use that one here. Then, instead of loading the whole matrix at once, the master node should just load columns as they are needed to send to the workers. All this function really needs to know is the matrix stats - dimensions and such. So we should here fill those fields in. Then make the initializeNode() function above read the needed columns from disk and send them out. */ M.numCols = M.numRows = 0; /* Change this to the real deal. */ /* Find out how many nodes there are. */ MPI_Comm_size(MPI_COMM_WORLD, &numNodes); nodeList[0].status = ST_MASTER; /****************************************************************/ /* If we have more than a handful of nodes, say more than 8, */ /* we should leave at least one `on call' in case another one */ /* dies. Why? Consider the alternative: if a node dies and we */ /* don't have a backup available, then we either have to */ /* give one node twice the work, or re-distribute and re-assign */ /* the matrix columns. This would: */ /* (1) Hugely complicate the code. */ /* (2) Waste bandwidth. */ /* (3) Waste time. */ /* Of course, we could assume that no node ever fails, but that */ /* is a very bad idea. The is the best compromise between */ /* robustness and efficiency that I can think of. */ /* If you don't like it, you can change this single line of */ /* code, but beware that the resulting code will not be fault */ /* tolerant at all! */ /****************************************************************/ numOnCall = ((numNodes >= 8) ? (MIN(1, 0.05*numNodes)) : 0); for (i=1; i<numNodes; i++) nodeList[i].status=ST_WORKING; for (i=0; i<numOnCall; i--) nodeList[numNodes-1-i].status = ST_ONCALL; /* How many columns does each node get? */ for (i=1; i<numNodes; i++) if (nodeList[i].status == ST_WORKING) numSlaves++; colsPerNode = M->numCols/numSlaves; /* Initialize the slave nodes with their needed columns. */ c0 = 0; c1 = c0 + colsPerNode; for (i=0,j=0; i<numSlaves; i++) { do { j++; } while (nodeList[j].status != ST_WORKING); nodeList[j].c0 = c0; nodeList[j].c1 = c1; initializeNode(&nodeList[j]); c0 = c1; c1 = MIN(c0+colsPerNode, M->numCols); } /* We should now be able to just do: */ srand(seed); seedBlockLanczos(seed); startTime = sTime(); msgLog("", "GGNFS-%s : mpi-matsolve", GGNFS_VERSION); msgLog("", "Running on %d (of %d) nodes.", numSlaves, numNodes); blstart = sTime(); if (!(deps = (long *)malloc(M.numCols*sizeof(long)))) { fprintf(stderr, "Severe memory allocation error!\n"); res = -1; } else { res = blockLanczos32(deps, mpi-multB32, mpi-multB_T32, NULL, M.numCols); blstop = sTime(); printf("Returned %d. Block Lanczos took %1.2lf seconds.\n", res, blstop-blstart); msgLog("", "BLanczosTime: %1.1lf", blstop-blstart); } /* Shutdown all of the nodes except this one. */ for (i=1; i<numNodes; i++) { MPI_Send(0, 0, MPI_INT, i, DIETAG, MPI_COMM_WORLD); } /* Now retrieve the actual dependencies (i.e., if there was a matrix pruning step, then we need to get back to the original matrix). Then store them to file. */ }
void OPMisc::initialise() { _KE.init(Sim->dynamics->getSystemKineticEnergy()); _internalE.init(Sim->calcInternalEnergy()); dout << "Particle Count " << Sim->N << "\nSim Unit Length " << Sim->units.unitLength() << "\nSim Unit Time " << Sim->units.unitTime() << "\nDensity " << Sim->getNumberDensity() * Sim->units.unitVolume() << "\nPacking Fraction " << Sim->getPackingFraction() << "\nTemperature " << getCurrentkT() / Sim->units.unitEnergy() << "\nNo. of Species " << Sim->species.size() << "\nSimulation box length <x y z> < "; for (size_t iDim = 0; iDim < NDIM; iDim++) dout << Sim->primaryCellSize[iDim] / Sim->units.unitLength() << " "; dout << ">\n"; Matrix kineticP; Vector thermalConductivityFS(0,0,0); _speciesMomenta.clear(); _speciesMomenta.resize(Sim->species.size()); _speciesMasses.clear(); _speciesMasses.resize(Sim->species.size()); BOOST_FOREACH(const Particle& part, Sim->particles) { const Species& sp = *(Sim->species[part]); const double mass = sp.getMass(part.getID()); kineticP += mass * Dyadic(part.getVelocity(), part.getVelocity()); _speciesMasses[sp.getID()] += mass; _speciesMomenta[sp.getID()] += mass * part.getVelocity(); thermalConductivityFS += part.getVelocity() * Sim->dynamics->getParticleKineticEnergy(part); } Vector sysMomentum(0,0,0); _systemMass = 0; for (size_t i(0); i < Sim->species.size(); ++i) { sysMomentum += _speciesMomenta[i]; _systemMass += _speciesMasses[i]; } _kineticP.init(kineticP); _sysMomentum.init(sysMomentum); //Set up the correlators double correlator_dt = Sim->lastRunMFT / 8; if (correlator_dt == 0.0) correlator_dt = 1.0 / sqrt(getCurrentkT()); _thermalConductivity.resize(correlator_dt, 10); _thermalConductivity.setFreeStreamValue(thermalConductivityFS); _viscosity.resize(correlator_dt, 10); _viscosity.setFreeStreamValue(kineticP); _thermalDiffusion.resize(Sim->species.size()); _mutualDiffusion.resize(Sim->species.size() * Sim->species.size()); for (size_t spid1(0); spid1 < Sim->species.size(); ++spid1) { _thermalDiffusion[spid1].resize(correlator_dt, 10); _thermalDiffusion[spid1] .setFreeStreamValue(thermalConductivityFS, _speciesMomenta[spid1] - (_speciesMasses[spid1] / _systemMass) * _sysMomentum.current()); for (size_t spid2(spid1); spid2 < Sim->species.size(); ++spid2) { _mutualDiffusion[spid1 * Sim->species.size() + spid2].resize(correlator_dt, 10); _mutualDiffusion[spid1 * Sim->species.size() + spid2].setFreeStreamValue (_speciesMomenta[spid1] - (_speciesMasses[spid1] / _systemMass) * _sysMomentum.current(), _speciesMomenta[spid2] - (_speciesMasses[spid2] / _systemMass) * _sysMomentum.current()); } } dout << "Total momentum < "; for (size_t iDim = 0; iDim < NDIM; iDim++) dout << _sysMomentum.current()[iDim] / Sim->units.unitMomentum() << " "; dout << ">\n"; std::time(&tstartTime); clock_gettime(CLOCK_MONOTONIC, &acc_tstartTime); std::string sTime(std::ctime(&tstartTime)); sTime[sTime.size()-1] = ' '; dout << "Started on " << sTime << std::endl; }
void OPMisc::output(magnet::xml::XmlStream &XML) { std::time_t tendTime; time(&tendTime); std::string sTime(std::ctime(&tstartTime)); //A hack to remove the newline character at the end sTime[sTime.size()-1] = ' '; std::string eTime(std::ctime(&tendTime)); //A hack to remove the newline character at the end eTime[eTime.size()-1] = ' '; dout << "Ended on " << eTime << "\nTotal Collisions Executed " << Sim->eventCount << "\nAvg Events/s " << getEventsPerSecond() << "\nSim time per second " << getSimTimePerSecond() << std::endl; const double V = Sim->getSimVolume(); const Matrix collP = collisionalP / (V * Sim->systemTime); const Matrix P = (_kineticP.mean() + collisionalP / Sim->systemTime) / V; XML << magnet::xml::tag("Misc") << magnet::xml::tag("Density") << magnet::xml::attr("val") << Sim->getNumberDensity() * Sim->units.unitVolume() << magnet::xml::endtag("Density") << magnet::xml::tag("PackingFraction") << magnet::xml::attr("val") << Sim->getPackingFraction() << magnet::xml::endtag("PackingFraction") << magnet::xml::tag("SpeciesCount") << magnet::xml::attr("val") << Sim->species.size() << magnet::xml::endtag("SpeciesCount") << magnet::xml::tag("ParticleCount") << magnet::xml::attr("val") << Sim->N << magnet::xml::endtag("ParticleCount") << magnet::xml::tag("SystemMomentum") << magnet::xml::tag("Current") << magnet::xml::attr("x") << _sysMomentum.current()[0] / Sim->units.unitMomentum() << magnet::xml::attr("y") << _sysMomentum.current()[1] / Sim->units.unitMomentum() << magnet::xml::attr("z") << _sysMomentum.current()[2] / Sim->units.unitMomentum() << magnet::xml::endtag("Current") << magnet::xml::tag("Average") << magnet::xml::attr("x") << _sysMomentum.mean()[0] / Sim->units.unitMomentum() << magnet::xml::attr("y") << _sysMomentum.mean()[1] / Sim->units.unitMomentum() << magnet::xml::attr("z") << _sysMomentum.mean()[2] / Sim->units.unitMomentum() << magnet::xml::endtag("Average") << magnet::xml::endtag("SystemMomentum") << magnet::xml::tag("Temperature") << magnet::xml::attr("Mean") << getMeankT() / Sim->units.unitEnergy() << magnet::xml::attr("MeanSqr") << getMeanSqrkT() / (Sim->units.unitEnergy() * Sim->units.unitEnergy()) << magnet::xml::attr("Current") << getCurrentkT() / Sim->units.unitEnergy() << magnet::xml::attr("Min") << 2.0 * _KE.min() / (Sim->N * Sim->dynamics->getParticleDOF() * Sim->units.unitEnergy()) << magnet::xml::attr("Max") << 2.0 * _KE.max() / (Sim->N * Sim->dynamics->getParticleDOF() * Sim->units.unitEnergy()) << magnet::xml::endtag("Temperature") << magnet::xml::tag("UConfigurational") << magnet::xml::attr("Mean") << getMeanUConfigurational() / Sim->units.unitEnergy() << magnet::xml::attr("MeanSqr") << getMeanSqrUConfigurational() / (Sim->units.unitEnergy() * Sim->units.unitEnergy()) << magnet::xml::attr("Current") << _internalE.current() / Sim->units.unitEnergy() << magnet::xml::attr("Min") << _internalE.min() / Sim->units.unitEnergy() << magnet::xml::attr("Max") << _internalE.max() / Sim->units.unitEnergy() << magnet::xml::endtag("UConfigurational") << magnet::xml::tag("ResidualHeatCapacity") << magnet::xml::attr("Value") << (getMeanSqrUConfigurational() - getMeanUConfigurational() * getMeanUConfigurational()) / (getMeankT() * getMeankT()) << magnet::xml::endtag("ResidualHeatCapacity") << magnet::xml::tag("Pressure") << magnet::xml::attr("Avg") << P.tr() / (3.0 * Sim->units.unitPressure()) << magnet::xml::tag("Tensor") << magnet::xml::chardata() ; for (size_t iDim = 0; iDim < NDIM; ++iDim) { for (size_t jDim = 0; jDim < NDIM; ++jDim) XML << P(iDim, jDim) / Sim->units.unitPressure() << " "; XML << "\n"; } XML << magnet::xml::endtag("Tensor") << magnet::xml::tag("InteractionContribution") << magnet::xml::chardata() ; for (size_t iDim = 0; iDim < NDIM; ++iDim) { for (size_t jDim = 0; jDim < NDIM; ++jDim) XML << collP(iDim, jDim) / Sim->units.unitPressure() << " "; XML << "\n"; } XML << magnet::xml::endtag("InteractionContribution") << magnet::xml::endtag("Pressure") << magnet::xml::tag("Duration") << magnet::xml::attr("Events") << Sim->eventCount << magnet::xml::attr("OneParticleEvents") << _singleEvents << magnet::xml::attr("TwoParticleEvents") << _dualEvents << magnet::xml::attr("VirtualEvents") << _virtualEvents << magnet::xml::attr("Time") << Sim->systemTime / Sim->units.unitTime() << magnet::xml::endtag("Duration") << magnet::xml::tag("EventCounters"); typedef std::pair<EventKey, size_t> mappair; BOOST_FOREACH(const mappair& mp1, _counters) XML << magnet::xml::tag("Entry") << magnet::xml::attr("Type") << getClass(mp1.first.first) << magnet::xml::attr("Name") << getName(mp1.first.first, Sim) << magnet::xml::attr("Event") << mp1.first.second << magnet::xml::attr("Count") << mp1.second << magnet::xml::endtag("Entry"); XML << magnet::xml::endtag("EventCounters") << magnet::xml::tag("Timing") << magnet::xml::attr("Start") << sTime << magnet::xml::attr("End") << eTime << magnet::xml::attr("EventsPerSec") << getEventsPerSecond() << magnet::xml::attr("SimTimePerSec") << getSimTimePerSecond() << magnet::xml::endtag("Timing") << magnet::xml::tag("PrimaryImageSimulationSize") << Sim->primaryCellSize / Sim->units.unitLength() << magnet::xml::endtag("PrimaryImageSimulationSize") << magnet::xml::tag("totMeanFreeTime") << magnet::xml::attr("val") << getMFT() << magnet::xml::endtag("totMeanFreeTime") << magnet::xml::tag("NegativeTimeEvents") << magnet::xml::attr("Count") << _reverseEvents << magnet::xml::endtag("NegativeTimeEvents") << magnet::xml::tag("Memusage") << magnet::xml::attr("MaxKiloBytes") << magnet::process_mem_usage() << magnet::xml::endtag("Memusage") << magnet::xml::tag("ThermalConductivity") << magnet::xml::tag("Correlator") << magnet::xml::chardata(); { std::vector<magnet::math::LogarithmicTimeCorrelator<Vector>::Data> data = _thermalConductivity.getAveragedCorrelator(); double inv_units = Sim->units.unitk() / ( Sim->units.unitTime() * Sim->units.unitThermalCond() * 2.0 * std::pow(getMeankT(), 2) * V); XML << "0 0 0 0 0\n"; for (size_t i(0); i < data.size(); ++i) XML << data[i].time / Sim->units.unitTime() << " " << data[i].sample_count << " " << data[i].value[0] * inv_units << " " << data[i].value[1] * inv_units << " " << data[i].value[2] * inv_units << "\n"; } XML << magnet::xml::endtag("Correlator") << magnet::xml::endtag("ThermalConductivity") << magnet::xml::tag("Viscosity") << magnet::xml::tag("Correlator") << magnet::xml::chardata(); { std::vector<magnet::math::LogarithmicTimeCorrelator<Matrix>::Data> data = _viscosity.getAveragedCorrelator(); double inv_units = 1.0 / (Sim->units.unitTime() * Sim->units.unitViscosity() * 2.0 * getMeankT() * V); XML << "0 0 0 0 0 0 0 0 0 0 0\n"; for (size_t i(0); i < data.size(); ++i) { XML << data[i].time / Sim->units.unitTime() << " " << data[i].sample_count << " "; for (size_t j(0); j < 3; ++j) for (size_t k(0); k < 3; ++k) XML << (data[i].value(j,k) - std::pow(data[i].time * P(j, k) * V, 2)) * inv_units << " "; XML << "\n"; } } XML << magnet::xml::endtag("Correlator") << magnet::xml::endtag("Viscosity") << magnet::xml::tag("ThermalDiffusion"); for (size_t i(0); i < Sim->species.size(); ++i) { XML << magnet::xml::tag("Correlator") << magnet::xml::attr("Species") << Sim->species[i]->getName() << magnet::xml::chardata(); std::vector<magnet::math::LogarithmicTimeCorrelator<Vector>::Data> data = _thermalDiffusion[i].getAveragedCorrelator(); double inv_units = 1.0 / (Sim->units.unitTime() * Sim->units.unitThermalDiffusion() * 2.0 * getMeankT() * V); XML << "0 0 0 0 0\n"; for (size_t i(0); i < data.size(); ++i) { XML << data[i].time / Sim->units.unitTime() << " " << data[i].sample_count << " "; for (size_t j(0); j < 3; ++j) XML << data[i].value[j] * inv_units << " "; XML << "\n"; } XML << magnet::xml::endtag("Correlator"); } XML << magnet::xml::endtag("ThermalDiffusion") << magnet::xml::tag("MutualDiffusion"); for (size_t i(0); i < Sim->species.size(); ++i) for (size_t j(i); j < Sim->species.size(); ++j) { XML << magnet::xml::tag("Correlator") << magnet::xml::attr("Species1") << Sim->species[i]->getName() << magnet::xml::attr("Species2") << Sim->species[j]->getName() << magnet::xml::chardata(); std::vector<magnet::math::LogarithmicTimeCorrelator<Vector>::Data> data = _mutualDiffusion[i * Sim->species.size() + j].getAveragedCorrelator(); double inv_units = 1.0 / (Sim->units.unitTime() * Sim->units.unitMutualDiffusion() * 2.0 * getMeankT() * V); XML << "0 0 0 0 0\n"; for (size_t i(0); i < data.size(); ++i) { XML << data[i].time / Sim->units.unitTime() << " " << data[i].sample_count << " "; for (size_t j(0); j < 3; ++j) XML << data[i].value[j] * inv_units << " "; XML << "\n"; } XML << magnet::xml::endtag("Correlator"); } XML << magnet::xml::endtag("MutualDiffusion") << magnet::xml::endtag("Misc"); }