source: CIVL/examples/mpi/seq/ser_prime.c@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[e48510a]1/******************************************************************************
2* FILE: ser_prime.c
3* DESCRIPTION:
4* This program generates primes. The approach taken is a "brute force"
5* method which requires increasingly greater amounts of cpu as the problem
6* size increases. It should lend itself well to an embarassingly parallel
7* solution since each prime can be computed independently of all other
8* primes.
9* AUTHOR: Blaise Barney 11/25/95 - adapted from version contributed by
10* Richard Ng & Wong Sze Cheong during MHPCC Singapore Workshop (8/22/95).
11* LAST REVISED: 04/12/05
12****************************************************************************/
13#include <stdio.h>
14#include <stdlib.h>
15#include <math.h>
16
17#define LIMIT 2500000 /* Increase this to find more primes */
18#define PRINT 100000 /* Print a line after this many numbers */
19
20
21int isprime(int n) {
22int i,squareroot;
23if (n>10) {
24 squareroot = (int) sqrt(n);
25 for (i=3; i<=squareroot; i=i+2)
26 if ((n%i)==0)
27 return 0;
28 return 1;
29 }
30/* Assume first four primes are counted elsewhere. Forget everything else */
31else
32 return 0;
33}
34
35
36int main(int argc, char *argv[])
37{
38int n, /* loop variables */
39 pc, /* prime counter */
40 foundone; /* most recent prime found */
41
42printf("Starting. Numbers to be scanned= %d\n",LIMIT);
43
44pc=4; /* Assume the primes less than 10 (2,3,5,7) are counted here */
45
46for (n=11; n<=LIMIT; n=n+2) {
47 if (isprime(n)) {
48 pc++;
49 foundone = n;
50 /***** Optional: print each prime as it is found
51 printf("%d\n",foundone);
52 *****/
53 }
54 if ( (n-1)%PRINT == 0 )
55 printf("Numbers scanned= %d Primes found= %d\n",n-1,pc);
56 }
57printf("Done. Largest prime is %d Total primes %d\n",foundone,pc);
58}
59
60
61
62
63
64
Note: See TracBrowser for help on using the repository browser.