Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ ./run.sh
- $ cat run.sh ----------------------------------------------
- #!/bin/bash
- echo "\$ cat run.sh ----------------------------------------------"
- cat run.sh
- echo "\$ rm -f simple.* 2>/dev/null ------------------------------"
- rm -f simple.* 2>/dev/null
- echo "\$ g++ -std=c++11 -pthread simple_3.cpp -o simple.3 --------"
- g++ -std=c++11 -pthread simple_3.cpp -o simple.3
- echo "\$ g++ -std=c++11 -pthread simple_3_2.cpp -o simple.3_2 ----"
- g++ -std=c++11 -pthread simple_3_2.cpp -o simple.3_2
- echo "\$ time ./simple.3 >simple.3.out ---------------------------"
- date +%M:%S.%N
- time ./simple.3 >simple.3.out
- date +%M:%S.%N
- echo "\$ time ./simple.3_2 >simple.3_2.out -----------------------"
- date +%M:%S.%N
- time ./simple.3_2 >simple.3_2.out
- date +%M:%S.%N
- echo "\$ diff simple.3.out simple.3_2.out ------------------------"
- diff simple.3.out simple.3_2.out
- echo "$?"
- echo "\$ diff simple_3.cpp simple_3_2.cpp ------------------------"
- diff simple_3.cpp simple_3_2.cpp
- $ rm -f simple.* 2>/dev/null ------------------------------
- $ g++ -std=c++11 -pthread simple_3.cpp -o simple.3 --------
- $ g++ -std=c++11 -pthread simple_3_2.cpp -o simple.3_2 ----
- $ time ./simple.3 >simple.3.out ---------------------------
- 54:51.414693127
- real 0m14.731s
- user 0m14.148s
- sys 0m0.540s
- 55:06.147527702
- $ time ./simple.3_2 >simple.3_2.out -----------------------
- 55:06.148773745
- real 0m11.722s
- user 0m15.024s
- sys 0m2.044s
- 55:17.872201307
- $ diff simple.3.out simple.3_2.out ------------------------
- 0
- $ diff simple_3.cpp simple_3_2.cpp ------------------------
- 24a25
- > static void solvePrime3_2(CPrimeNumbers *sno, const uint v,const uint max); // Multithreading version: mark all N*v numbers (N - integer, N*v<=max) as non-prime
- 29a31
- > void Initiate3_2(const uint max=6); // Marking-forward algorithm, multithreading using C++11, std::thread
- 37a40,70
- > /*static*/ void CPrimeNumbers::solvePrime3_2(CPrimeNumbers *sno, const uint head, const uint max)
- > {
- > if ( sno->numbers[sno->NumberToIndex(head)]==1 ) { // Is prime/unchecked yet
- > if (!sno->IsPrime(head)) { // Is not prime
- > sno->numbers[sno->NumberToIndex(head)]=0;
- > }
- > else{ // Is prime
- > MarkNonPrime3(sno,head,max);
- > }
- > }
- > };
- >
- > void CPrimeNumbers::Initiate3_2(const uint max)
- > {
- > uint head,i;
- > vector<thread> threads;
- >
- > numbers.assign(NumberToIndex(max)+1,1);
- >
- > for (head=3;head<=max;head+=2) {
- > if ( threads.size()==MAX_THREAD) {
- > threads[0].join();
- > threads.erase(threads.begin());
- > }
- > threads.push_back( thread(solvePrime3_2,this,head,max) );
- > }
- >
- > for (auto t=threads.begin();t!=threads.end();t++)
- > t->join();
- > };
- >
- 224c257
- < s.Initiate3(200000);
- ---
- > s.Initiate3_2(200000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement