int main () { Kokkos::initialize (); srand (61391); // Set the random seed int nnumbers = 100000; view_type data ("RND", nnumbers); view_type result ("Prime", nnumbers); count_type count ("Count"); host_view_type h_data = Kokkos::create_mirror_view (data); host_view_type h_result = Kokkos::create_mirror_view (result); host_count_type h_count = Kokkos::create_mirror_view (count); typedef view_type::size_type size_type; // Fill the 'data' array on the host with random numbers. We assume // that they come from some process which is only implemented on the // host, via some library. (That's true in this case.) for (size_type i = 0; i < data.dimension_0 (); ++i) { h_data(i) = rand () % nnumbers; } Kokkos::deep_copy (data, h_data); // copy from host to device Kokkos::parallel_for (data.dimension_0 (), findprimes (data, result, count)); Kokkos::deep_copy (h_count, count); // copy from device to host printf ("Found %i prime numbers in %i random numbers\n", h_count(), nnumbers); Kokkos::finalize (); }
int main() { Kokkos::initialize(); srand(61391); int nnumbers = 100000; view_type data("RND",nnumbers); view_type result("Prime",nnumbers); count_type count("Count"); host_view_type h_data = Kokkos::create_mirror_view(data); host_view_type h_result = Kokkos::create_mirror_view(result); host_count_type h_count = Kokkos::create_mirror_view(count); typedef view_type::size_type size_type; for (size_type i = 0; i < data.dimension_0(); ++i) { h_data(i) = rand () % nnumbers; } Kokkos::deep_copy(data,h_data); Kokkos::parallel_for(data.dimension_0(),findprimes(data,result,count)); Kokkos::deep_copy(h_count,count); printf("Found %i prime numbers in %i random numbers\n",h_count(),nnumbers); Kokkos::finalize(); }
int main(int argc, const char * argv[]){ int n, k, i; if(argc > 1){ n = atoi(argv[1]); //Set n to the command line arguments } else { n = 5; //Set n to 5 by default } printf("Calculating primes from 1 to %d using Sieve of Eratosthenes method...\n", n); int *primes; int numprimes = findprimes(primes, n); printf("Primes:\n"); for(i=1;i<=n;i++){ printf("%d: %d\n", i, *(primes + i-1)); } printf("Number of primes is %d.\n", numprimes); return 0; }
int main(int argc, const char * argv[]){ int n, k, i; if(argc > 1){ n = atoi(argv[1]); //Set n to the command line arguments } else { n = 5; //Set n to 5 by default } printf("Calculating primes from 1 to %d using Sieve of Eratosthenes method...\n", n); int *numarray = (int *)malloc(n * sizeof(int)); int numprimes = findnumprimes(numarray, n); int *primes = (int *)malloc(numprimes * sizeof(int)); findprimes(numarray, primes, n, numprimes); printf("Primes:\n"); for(i=0;i<numprimes;i++){ printf("%d\n", *(primes + i)); } printf("Number of primes is %d.\n", numprimes); free(numarray); free(primes); return 0; }