From: Click to open the link
Computing from 1 ~ Sum of 1e10
// Paralle. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <OMP. h> # include <stdio. h> # include <stdlib. h> # include <windows. h> # include <time. h> # define num_threads 4int _ tmain (INT argc, _ tchar * argv []) {omp_set_num_threads (num_threads); long sum = 0; long sumtmp [num_threads]; clock_t T1 = clock (); # pragma OMP parallel {long I; long id = omp_get_thread_num (); long temp = 0l; # pragma OMP forfor (I = 1; I <= 1000000000; I ++) {temp + = I;} sumtmp [ID] = temp;} For (long I = 0; I <num_threads; I ++) {sum + = sumtmp [I];} clock_t t2 = clock (); printf ("sum = % LLD \ n", sum ); printf ("parallel time = % d \ n", (t2-t1); sum = 0; T1 = clock (); For (long I = 1; I <= 1000000000; I ++) sum + = I; t2 = clock (); printf ("sum = % LLD \ n", sum ); printf ("Serial Time = % d \ n", (t2-t1); System ("pause"); Return 0 ;}
Parallel Computing _ simple parallel computing instance