////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Factor C++ Program // This program spawns children, who will help to determine the prime numbers. // To compile: g++ Factor.cpp -o Factor // To run: ./runFactor > temp.out // To monitor system resources: (Linux): Applications->System Tools->System Monitor->Resources // Use Spreadsheet Applications->Office->LibreOffice Calc to show efficiency of multiple threads. ////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include using namespace std; #define numChild 4 #define total 600000 class Factor { public: Factor() { } void child(int begin, int end); private: int start_s; // start time }; int main() { int i; int range = total/numChild; int begin=0; int stat; cerr << "Run Factor " << total << ":" << numChild << endl; Factor factor; // Spawn children processes for (i=0; ival/2) cout << "F:" << val << endl; } // Calculate execution time in ms and print int stop_s=clock(); cerr << "time: " << (stop_s-start_s)/double(CLOCKS_PER_SEC)*1000 << endl; exit(0); }