Skip to content
Snippets Groups Projects
Commit 7b1fa155 authored by Hailu, Dawit's avatar Hailu, Dawit
Browse files

Hello.c changed to a parallel prime search algorithm. it took 1:16 sec to find...

Hello.c changed to a parallel prime search algorithm. it took 1:16 sec to find all the primes between two and 800,000. While the unparallel took 2:36 sec.
parent fb5e0ccf
No related branches found
No related tags found
No related merge requests found
......@@ -3,37 +3,23 @@
NAME:
Hello
DESCRIPTION:
Description:
this is about the simplest program thinkable to demonstrate
parallel execution with OpenMP
VERSION(S):
1. original version j. behrens 6/2021
COPYRIGHT INFORMATION:
Copyright (C) 2021 Jörn Behrens <joern.behrens@uni-hamburg.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*****************************************************************/
#include <stdio.h>
#include <omp.h>
int main(int argc, char** argv)
{
/* local declarations */
int thrd_id;
......@@ -43,6 +29,21 @@ int main(int argc, char** argv)
{
thrd_id = omp_get_thread_num();
printf("Hello from process Number %d\n", thrd_id);
int i,j;
int count=100000;
for(i=thrd_id*count+2;i<count*(thrd_id+1)+2;i++){
for (j = 2; j<=i; j++)
{
if(i%j==0)
{
break;
}
}
if(i==j){
printf("%d is a prime \n,",i);
}
}
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment