Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <omp.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- int threadNumber = 3;
- float v1[5], v2[5], v3[5],v0[5];
- void PrintArray(float array[5], char a);
- void Average(float array[5], char a);
- cout << "Broj niti:"<< omp_get_num_threads()<<"\n";
- for(int i=0;i<5;i++)
- {
- v1[i]=(float)(1+i)/(1);
- v2[i]=(float)(2+i)/(2);
- v3[i]=(float)(3+i)/(3);
- }
- omp_set_num_threads(threadNumber);
- //Ispis niti
- #pragma omp parallel
- {
- if(omp_get_thread_num()==0)
- {
- PrintArray(v1,'1');
- Average(v1,'1');
- cout << "Thread num:"<<omp_get_thread_num()<<"\n";
- }
- else if(omp_get_thread_num()==1)
- {
- PrintArray(v2,'2');
- Average(v2,'2');
- cout << "Thread num:"<<omp_get_thread_num()<<"\n";
- }
- else if(omp_get_thread_num()==2)
- {
- PrintArray(v3,'3');
- Average(v3,'3');
- cout << "Thread num:"<<omp_get_thread_num()<<"\n";
- }
- }
- #pragma omp parallel for
- for(int i=0;i<5;i++)
- {
- v0[i]=v1[i]+v2[i]+v3[i];
- }
- cout<<"Rezultat:"<<"\n";
- for(int i=0;i<5;i++)
- {
- cout<<v0[i]<<"\n";
- }
- //globalna srednja
- float glob = 0;
- for(int i=0;i<5;i++)
- {
- glob = glob+v0[i];
- }
- cout<<"Globalna srednja vrijednost"<<(glob)/15<<"\n";
- }
- void PrintArray(float array[5],char a)
- {
- for(int i =0;i<5;i++)
- {
- cout << a << array[i] << "\n";
- }
- }
- void Average(float array[5],char a)
- {
- int sum=0;
- for(int i =0;i<5;i++)
- {
- sum = sum + array[i];
- }
- float avg = (float)(sum)/(5);
- cout << "Srednja vrijednost:" << avg << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement