Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
2.1.1 Prime numbers in different threads with thread ID
#include <stdio.h> #include <stdlib.h> #include <omp.h> int main(void) { int i,j,k,n = 100,count = 0; int *arr = (int *)malloc(n*sizeof(int)); for(i = 0;i<n;i++) { arr[i] = rand()%1000; } //check prime printf("\nPrime Numbers\tThread id"); #pragma omp parallel for for(i = 0;i<n;i++) { int flag = 1; k = arr[i]; for(j = 2; j<(k/2);j++) { if(k%j == 0) { flag = 0; break; } } if(flag == 1) { count++; printf("\n %d\t\t %d",k,omp_get_thread_num()); } } printf("\nTotal Count of Prime Numbers = %d",count); return 0; }
run
|
edit
|
history
|
help
0
Swap.c
G
B_141202_Cadenas01
C_141127:MatricesUnSoloIndice
Length width.c
MailingList
DDD
EL PANGRAMA PERFECTO
bitmask
add.c