aaadam Temat założony przez niniejszego użytkownika |
[c++] [openmp] [task] [linux] [sfml] brak przyspieszenia » 2019-01-06 13:41:24 witam, staram się zrównoleglić trójkąt sierpińskiego za pomocą openmp przy użyciu pragmy task, niestety gdy dodałem te pragmy to czas wykonywania programu nie zmienił się. Tak kompiluję : g++ -c sierpinski.cpp -I/usr/include -o sierpinski.o g++ sierpinski.o -lsfml-graphics -lsfml-window -lsfml-system -lgomp -openmp -o sierpinski aplikacja printuje ciągle : Thread rank: 0 Setting vertical sync not supported 28.7822 czas mniej więcej taki sam ktoś coś może doradzić ?? kod poniżej #include <SFML/Graphics.hpp>
#include <omp.h> #include <time.h> #include <iostream>
void drawSierpinski( float x1, float y1, float x2, float y2, float x3, float y3, sf::RenderWindow * window ); void subTriangle( int n, float x1, float y1, float x2, float y2, float x3, float y3, sf::RenderWindow * window );
int depth = 15;
int main( int argc, char * argv[] ) { printf( "Thread rank: %d\n", omp_get_thread_num() ); int SIZE = 700; int h = SIZE; int w = SIZE; sf::RenderWindow window( sf::VideoMode( SIZE, SIZE ), "SFML works!" ); sf::CircleShape shape( 100.f ); shape.setFillColor( sf::Color::Green ); clock_t start, finish; start = clock(); drawSierpinski( 10, h - 10, w - 10, h - 10, w / 2, 10, & window ); finish = clock(); double processing_time =( double( finish - start ) / CLOCKS_PER_SEC ); std::cout << processing_time << std::endl; window.display(); while( window.isOpen() ) { sf::Event event; while( window.pollEvent( event ) ) { if( event.type == sf::Event::Closed ) window.close(); } } return( 0 ); }
void drawSierpinski( float x1, float y1, float x2, float y2, float x3, float y3, sf::RenderWindow * window ) { sf::Vertex line[] = { sf::Vertex( sf::Vector2f( int( x1 ), int( y1 ) ) ), sf::Vertex( sf::Vector2f( int( x2 ), int( y2 ) ) ) }; window->draw( line, 2, sf::Lines ); sf::Vertex line2[] = { sf::Vertex( sf::Vector2f( int( x1 ), int( y1 ) ) ), sf::Vertex( sf::Vector2f( int( x3 ), int( y3 ) ) ) }; window->draw( line2, 2, sf::Lines ); sf::Vertex line3[] = { sf::Vertex( sf::Vector2f( int( x2 ), int( y2 ) ) ), sf::Vertex( sf::Vector2f( int( x3 ), int( y3 ) ) ) }; window->draw( line3, 2, sf::Lines ); subTriangle ( 1, ( x1 + x2 ) / 2, ( y1 + y2 ) / 2, ( x1 + x3 ) / 2, ( y1 + y3 ) / 2, ( x2 + x3 ) / 2, ( y2 + y3 ) / 2, window ); }
void subTriangle( int n, float x1, float y1, float x2, float y2, float x3, float y3, sf::RenderWindow * window ) { sf::Vertex line[] = { sf::Vertex( sf::Vector2f( int( x1 ), int( y1 ) ) ), sf::Vertex( sf::Vector2f( int( x2 ), int( y2 ) ) ) }; window->draw( line, 2, sf::Lines ); sf::Vertex line2[] = { sf::Vertex( sf::Vector2f( int( x1 ), int( y1 ) ) ), sf::Vertex( sf::Vector2f( int( x3 ), int( y3 ) ) ) }; window->draw( line2, 2, sf::Lines ); sf::Vertex line3[] = { sf::Vertex( sf::Vector2f( int( x2 ), int( y2 ) ) ), sf::Vertex( sf::Vector2f( int( x3 ), int( y3 ) ) ) }; window->draw( line3, 2, sf::Lines ); #pragma omp parallel { #pragma omp sigle { if( n < depth ) { #pragma omp task shared(depth) { subTriangle ( n + 1, ( x1 + x2 ) / 2 +( x2 - x3 ) / 2, ( y1 + y2 ) / 2 +( y2 - y3 ) / 2, ( x1 + x2 ) / 2 +( x1 - x3 ) / 2, ( y1 + y2 ) / 2 +( y1 - y3 ) / 2, ( x1 + x2 ) / 2, ( y1 + y2 ) / 2, window ); } #pragma omp task shared(depth) { subTriangle ( n + 1, ( x3 + x2 ) / 2 +( x2 - x1 ) / 2, ( y3 + y2 ) / 2 +( y2 - y1 ) / 2, ( x3 + x2 ) / 2 +( x3 - x1 ) / 2, ( y3 + y2 ) / 2 +( y3 - y1 ) / 2, ( x3 + x2 ) / 2, ( y3 + y2 ) / 2, window ); } #pragma omp task shared(depth) { subTriangle ( n + 1, ( x1 + x3 ) / 2 +( x3 - x2 ) / 2, ( y1 + y3 ) / 2 +( y3 - y2 ) / 2, ( x1 + x3 ) / 2 +( x1 - x2 ) / 2, ( y1 + y3 ) / 2 +( y1 - y2 ) / 2, ( x1 + x3 ) / 2, ( y1 + y3 ) / 2, window ); } } } } }
|