multithreading - Basic Threading in C++ Program Issue -
#include <stdlib.h> #include <iostream> #include <thread> using namespace std; int threshold = 20; __m128i set1 = _mm_set1_epi8(1); __m128i set0 = _mm_set1_epi8(0); __m128i set2 = _mm_set1_epi8(2); #define capture_perf(x) x = capturetime(); static unsigned long capturetime() { double curtime = 1000 * (double)clock() / clocks_per_sec; return (unsigned long)curtime; } void threadfunc1(unsigned char *threshold_tab ,int start , int end ) { (int = start;i < end;i += 16) _mm_storeu_si128((__m128i *)(threshold_tab + + 255), set1); } void threadfunc2(unsigned char *threshold_tab ,int start , int end ) { (int = start;i <= end;i += 16) _mm_storeu_si128((__m128i *)(threshold_tab + + 255), set0); } void threadfunc3(unsigned char *threshold_tab ,int start , int end ) { (int = start;i <= end;i += 16) _mm_storeu_si128((__m128i *)(threshold_tab + + 255), set2); } int main() { int i; unsigned long int start, end; unsigned char threshold_tab[530]; __m128i set1 = _mm_set1_epi8(1); __m128i set0 = _mm_set1_epi8(0); __m128i set2 = _mm_set1_epi8(2); capture_perf(start); for(int j = 0 ; j < 10000; j++) { thread thread1(threadfunc1, threshold_tab, -255,-threshold); thread1.join(); }; capture_perf(end); unsigned long int time = (end - start); cout << " time taken :"<< time <<"msec"<< endl; return 0; }
there 2 pieces of code runs without threading , and threading. system 4 core systems. ran 10000 times see performance improvement of threading. without threading ran in 1msec threading ran 27msec. why ? newbie threading . please me on .
Comments
Post a Comment