int main(int argc, char **argv) { std::string path = ros::package::getPath("aida"); file.open((path + "/data").c_str(), ios::in | ios::out | ios::binary); ROS_INFO("%s", (path + "/data").c_str()); if (file.fail()) ROS_FATAL("Cannot open data file for learning algorithm."); ros::init(argc, argv, "la"); ros::NodeHandle n; ros::ServiceServer service = n.advertiseService("get_direction", getDirection); ros::ServiceServer update_sub = n.advertiseService("result", update); ros::Rate loop_rate(LOOP_RATE); while (ros::ok()) { file.flush(); ros::spinOnce(); loop_rate.sleep(); } file.close(); return 0; }
void CreateConfig(fstream &config) { HINSTANCE hInst = GetModuleHandle(NULL); HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(DFT_CONFIG), L"TEXT"); HGLOBAL hMem = LoadResource(hInst, hRes); config << (char*)LockResource(hMem); config.flush(); FreeResource(hMem); };
void ReadAlignChunk::chunkFstreamCat (fstream &chunkOut, ofstream &allOut, bool mutexFlag, pthread_mutex_t &mutexVal){ chunkOut.flush(); chunkOut.seekg(0,ios::beg); if (mutexFlag) pthread_mutex_lock(&mutexVal); allOut << chunkOut.rdbuf(); allOut.clear(); if (mutexFlag) pthread_mutex_unlock(&mutexVal); chunkOut.clear(); chunkOut.seekp(0,ios::beg); //set put pointer at the beginning };
void writeCMDLineArgsToLog(char* argv[]) { logfile << endl; logfile << "# Arguments:"; for(unsigned int i = 0; i < sizeof(argv); i++) { logfile << " " << argv[i]; } logfile << endl; logfile.flush(); }
SocketConnectivity::~SocketConnectivity() { if(m_armTrackingSocket != INVALID_SOCKET) { closesocket(m_armTrackingSocket); } WSACleanup(); #ifdef ADEEL_DEBUG debugOut.flush(); debugOut.close(); #endif }
/************************************************************************ * Maintainence and Administrative * ************************************************************************/ bool JobClass::WriteJobFile(fstream &JobStream) const { const vector <string> TheTagWords = InitTagWords(); JobStream << "<" << TheTagWords[0] << ">\n"; for (VolumeIter_Const AVol = myVolumes.begin(); AVol != myVolumes.end(); AVol++) { AVol->second.WriteJobList(AVol->first, JobStream); } JobStream << "</" << TheTagWords[0] << ">\n"; JobStream.flush(); // makes sure everything has been written return(JobStream.good()); }
void System::output_GrandResistanceMatrix(fstream &output){ int n11 = np*11; int datasize = n11*n11*sizeof(grandResistanceMatrix[0]); // output << np ; // int writepoint = output.tellp(); // output.seekp(writepoint, ios::beg); // cerr << sizeof(grandResistanceMatrix) << endl; output.write((char *) grandResistanceMatrix, datasize); output.flush(); //grandResistanceMatrix }
void writeGeneralInfoToLog(unsigned int countState, unsigned int countOutput, unsigned int countInput, unsigned int countParam, unsigned int countOptParam, unsigned int countObsParam, double numberOfsteps) { logfile << endl; logfile << "# GENERAL STATISTICS:" << endl; logfile << "# number of states: " << countState << endl; logfile << "# number of outputs: " << countOutput << endl; logfile << "# number of inputs: " << countInput << endl; logfile << "# number of parameters: " << countParam << endl; logfile << "# number of optimizer parameters: " << countOptParam << endl; logfile << "# number of observer parameters: " << countObsParam << endl; logfile << "# number of steps: " << numberOfsteps << endl; logfile << endl; logfile.flush(); }
void writeStepToLog(double step, double xcur[], unsigned int countState, double ycur[], unsigned int countOutput, double ucur[], unsigned int countInput, double pcur[], unsigned int countParam) { logfile << step << "\t"; for(unsigned int i = 0; i < countState; i++) { logfile << round(xcur[i],5) << "\t"; } for(unsigned int i = 0; i < countOutput; i++) { logfile << round(ycur[i],5) << "\t"; } for(unsigned int i = 0; i < countInput; i++) { logfile << round(ucur[i],5) << "\t"; } for(unsigned int i = 0; i < countParam; i++) { logfile << round(pcur[i],5) << "\t"; } logfile << endl; logfile.flush(); }
void CPUBenchmark::taskCreationTime(fstream &file) { cout << "4. Task creation time starts:" << endl; double overhead; double sum = 0; cout << "4.1 Time to create and run a process: "; cout.flush(); file.open(PROCESS_CREATION_TIME_FILE, ios::out); if(file.is_open()) { for(int i = 0; i < OP_TIMES; i++) { overhead = getProcessCreationTime(); file << overhead << "\n"; file.flush(); sum += overhead; } cout << (sum / OP_TIMES) << " cycles" << endl; file.close(); } else { cout << "Can't open file-" << PROCESS_CREATION_TIME_FILE << endl; } cout << "4.2 Time to create and run a kernel-managed thread: "; sum = 0; file.open(THREAD_CREATION_TIME_FILE, ios::out); if(file.is_open()) { for(int i = 0; i < OP_TIMES; i++) { overhead = getKernelThreadCreationTime(); file << overhead << "\n"; sum += overhead; } cout << (sum / OP_TIMES) << " cycles" << endl; file.close(); } else { cout << "Can't open file-" << THREAD_CREATION_TIME_FILE << endl; } }
void SocketConnectivity::SendPositionUpdate(float x, float y, float z) { // copy coordinates into m_positionUpdateBuffer memcpy_s( (void *)(m_positionUpdateBuffer), 4, (const void *)(&x), sizeof(x) ); memcpy_s( (void *)(m_positionUpdateBuffer + 4), 4, (const void *)(&y), sizeof(y) ); memcpy_s( (void *)(m_positionUpdateBuffer + 8), 4, (const void *)(&z), sizeof(z) ); // Send the message char *currStringPtr = m_positionUpdateBuffer; unsigned int totalBytesWritten = 0; int currBytesWritten = -1; while(totalBytesWritten < POSITION_UPDATE_BUFFER_LENGTH) { currBytesWritten = send(m_armTrackingSocket, currStringPtr, POSITION_UPDATE_BUFFER_LENGTH - totalBytesWritten, 0); if (currBytesWritten == SOCKET_ERROR) { MessageBox(m_hWnd, TEXT("SocketConnectivity::SendMessage(...):- send(...) failed"), g_szAppTitle, MB_OK | MB_ICONHAND); DestroyWindow(m_hWnd); } totalBytesWritten += currBytesWritten; currStringPtr += currBytesWritten; } #ifdef ADEEL_DEBUG debugOut << x << ", " << y << ", " << z << endl; debugOut.flush(); #endif return; }
void main(){ //create the result file resultFile.open("hovering_results.txt", std::fstream::app | fstream::in | fstream::out); resultFile << "---------------New Experiment--------------------" << endl; InitializeDrone(); getchar(); cout << " Set Home Position :" << endl; //set the current location as the home location. LaunchDroneOrSetHome(); //get the current state AstecDroneState currentDroneState; POSITION currentWP; currentWP.X = 0; currentWP.Y = 0; currentDroneState = GetUpdatedDroneState(); while (!CheckIfReachedDestination(currentWP)) { GotoWayPoint(currentWP.X, currentWP.Y, DEFAULT_HEIGHT); } //start taking the hovering readings. int i = 0; while (i < 1000) { currentDroneState = GetUpdatedDroneState(); //PrintCurrentDroneState(); DumpLocation(currentDroneState); resultFile.flush(); i++; } resultFile.close(); CloseSerialPort(); }
void readFile(fstream &file, bool isSequential) { int fd; uint64_t start, end; double average, total = 0, totalAverage = 0; const char* fileName; warmup(); double overhead = getReadOverhead(); void* buffer = malloc(BLOCK_SIZE); pid_t pids[TEST_FILE_NUMBER]; // using TEST_FILE_NUMBER as thread number for(int i = 1; i < TEST_FILE_NUMBER; i++) { file << "Company process number=" << i << "\n"; for(int j = 0; j < i; j++) { // fork new process pids[j] = fork(); if(pids[j] < 0) { cout << "Can't fork a new process" << endl; abort(); } else if(pids[j] == 0) { // enter the child process, do pure read process without any fetching data pureRead(1 + j, isSequential); exit(0); } } totalAverage = 0; // parent process finishing fetching performance data for (int j = 0; j < TEST_TIMES; j++) { fileName = (TEST_FILE_PREFIX + to_string(1)).c_str(); fd = open(fileName, O_SYNC | O_RDONLY); if(fd < 0) { cout << "Can't open the test file, please create a test file first: "<< fileName << endl; return; } // http://stackoverflow.com/questions/2299402/how-does-one-do-raw-io-on-mac-os-x-ie-equivalent-to-linuxs-o-direct-flag if(fcntl(fd, F_NOCACHE, 1) < 0) { cout << "Can't close cache of the test file" << endl; return; } // call purge to clear cache // system("purge"); total = 0; if(isSequential) { for(int k = 0; k < BLOCK_NUMBER; k++) { start = rdtscStart(); read(fd, buffer, BLOCK_SIZE); end = rdtscEnd(); total += (double) end - (double) start - overhead; } } else { off_t offset; for(int k = 0; k < BLOCK_NUMBER; k++) { start = rdtscStart(); offset = rand() % BLOCK_NUMBER; // using lseek to set offset lseek(fd, offset, SEEK_SET); read(fd, buffer, BLOCK_SIZE); end = rdtscEnd(); total += (double) end - (double) start - overhead; } } average = (total / BLOCK_NUMBER) * 0.37 / 1000000; file << average << "\n"; file.flush(); totalAverage += average; close(fd); } cout << "Company thread count = " << i << " average cycles = " << totalAverage / TEST_TIMES << endl; wait(NULL); } // close file and free memory free(buffer); }
void closeCPUTimeMeasLogFile() { measLog.flush(); measLog.close(); }
void closeLogFile() { logfile.flush(); logfile.close(); }
void Run(int swarmSize = 10, int generations=Global::Max, int averageRunsPerInstance=5, int runTimePerInstance=600) { assert(Parms.size() > 1); assert(Instances.size() > 0); double delta, rand; AlgoParms* algoParms1; AlgoParms* algoParms2; for (int i=0; i<swarmSize; ++i) Particles.push_back(new Particle(Parms)); for (int gen=0; gen < generations; ++gen) { for (int _p=0; _p<swarmSize; ++_p) { int _p2; while ((_p2 = Global::Rand(swarmSize)) != _p); Particle& p = *Particles[_p]; Particle& p2 = *Particles[_p2]; Particle* pTest = new Particle(Parms); for (int coord=0; coord<Parms.size(); ++coord) { delta = fabs(p[coord] - p2[coord]); // generate random number inclusively between [-delta, delta] rand = Global::RandDouble(-delta, delta); (*pTest)[coord] = min<double>(max<double>(0, p[coord] + rand), 1); } // Run on P double pDeviation=0, pTestDeviation=0; Result* result; for (int i=0; i<Instances.size(); ++i) { Runner run(*Instances[i], averageRunsPerInstance, runTimePerInstance, Global::Max); p.Apply(*Algo, Instances[i]->Size); // Apply Particle to Algo parameters. algoParms1 = Algo->GetParms(); result = Algo->Run(run); pDeviation += result->Deviation.Mean(); Means[0][i] = result->Deviation.Mean(); delete result; } // Run on PTest for (int i=0; i<Instances.size(); ++i) { Runner run(*Instances[i], averageRunsPerInstance, runTimePerInstance, Global::Max); p.Apply(*Algo, Instances[i]->Size); // Apply Particle to Algo parameters. algoParms2 = Algo->GetParms(); result = Algo->Run(run); pTestDeviation += result->Deviation.Mean(); Means[1][i] = result->Deviation.Mean(); delete result; } if (pDeviation < Best || pTestDeviation < Best) { Particle &pBest = pDeviation < pTestDeviation ? p : *pTest; AlgoParms *ap = pDeviation < pTestDeviation ? algoParms1 : algoParms2; Best = min<double>(pDeviation, pTestDeviation); int index = pDeviation < pTestDeviation ? 0 : 1; Log << Best << " ("; for (int i = 0; i<Instances.size(); ++i) Log << Instances[i]->InstanceName << ":" << Means[index][i] << " "; Log << ") " << ap->ToString() << endl; Log.flush(); delete algoParms1; delete algoParms2; } if (pTestDeviation < pDeviation) { delete Particles[_p]; Particles[_p] = pTest; } else { delete pTest; } } } }
void BeforeFork(THREADID threadid, const CONTEXT* ctxt, VOID * arg) { fout.flush(); }
void Local_File::flush() { file.flush(); }