Parallel dasturlash savollar num threads optsiyasi G’afurov Ibrohim


Download 26.9 Kb.
bet2/4
Sana09.04.2023
Hajmi26.9 Kb.
#1346434
1   2   3   4
Bog'liq
Parallel dasturlash savollar

If optsiyasi

  1. Foydalanuvchidan son kiritish talab qilinsin va bu sonning n – darajasini chiqaruvchi dastur tuzing . if optsiyasidan foydalanib shartli parallellikni hosil qiling . Agar kiritgan sonimiz 9 dan katta bo’lsa parallel directive ishga tushsin . Dasturni 3 ta oqim orqali ishga tushiring.

#include
#include
#include
using namespace std;
int main()
{
int son,n;
cout<< " Son kiriting : ";
cin>>son;
cout<< " Nechanchi darajasi chiqarilsin : ";
cin>>n;

#pragma omp parallel if(son>=10) num_threads(3)


{
cout << son << " sonining " << n << " - darajasi : " << pow(son,n) <}
return 0;
}

  1. Foydalanuvchidan ism kiritish so’ralsin . if optsiyasidan foydalanib shartli parallellikni hosil qiling . . Agar foydalanuvchining ismining uzunligi 5 dan katta bo’lsa parallel directiva ishga tushsin. Dasturni 2 ta oqim orqli ishga tushiring .

#include
#include
#include
using namespace std;
int main()
{
string name;
int len;
cout<< " Ismingizni kiriting : ";
cin>>name;
len=name.size();
#pragma omp parallel if(len>5) num_threads(2)
{
cout << "Foydalanuvchi ismi : " << name <}
return 0;
}

  1. “Assalomu alaykum “ so’zini ekranga n marta chiqaruvchi dastur tuzing . if optsiyasidan foydalanib shartli parallellikni hosil qiling. Agar n >50 bo’lsa parallel directiva ishga tushsin. Dasturni 7 ta oqim orqli ishga tushiring .

#include
#include
using namespace std;
int main()
{
string hi="Assalomu alaykum";
int n;
cout<< " Matn necha marotaba chiqarilsin :";
cin>>n;
#pragma omp parallel for if(n>50) num_threads(7)
for (int i=0; i{
cout << hi << " oqimlar soni - " << omp_get_num_threads()<}
return 0;
}

  1. Uchburchak tomonlari berilgan uning yuzinini topuvchi funksiya yarating . if optsiyasidan foydalanib shartli parallellikni hosil qiling . Agar uchburchak tomolari , uchburchak yasash qoidalariga to’g’ri kelsa parallel directiva ishga tushsin. Dasturni 5 ta oqim orqli ishga tushiring .

#include
#include
using namespace std;
float yuzi(float a, float b, float c){
return a*b*c;
}
int main()
{
float a,b,c;
cin>>a>>b>>c;
#pragma omp parallel for if(a+b>c and a+c>b and c+b>a) num_threads(5)
{
cout << " Uchburchak yuzi : " << yuzi(a,b,c) << " oqimlar soni : " << omp_get_num_threads()<}
return 0;
}

Download 26.9 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling