Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.70 KB | None | 0 0
  1. // ConsoleApplication3.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "omp.h"
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. int _tmain(int argc, _TCHAR* argv[])
  11. {
  12.    
  13.     setlocale(LC_ALL, "RUS");
  14.  
  15.     cout << "Bведите число потоков " << endl;
  16.     int threads;
  17.     cin >> threads;
  18.     int n;
  19.     cout << "Введите N" << endl;
  20.     cin >> n;
  21.     omp_set_num_threads(threads);
  22.     int sum = 0;
  23.     int i = 1;
  24. #pragma omp parallel reduction(+:sum)
  25.     {
  26.         while (i < n)
  27.         {
  28.             sum += i;
  29.             i++;
  30.            
  31.         }
  32.         printf("sum=%d\n", sum);
  33.  
  34.        
  35.        
  36.     }
  37.     cout <<"Sum = "<< sum << endl;;
  38.     system("pause");
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement