int main(int argc, char *argv[]) { int threadCount, startP; if (argc > 2) { Usage(); return -1; } if (argc >= 2) { // Read the starting value from the parameter list startP = atoi(argv[1]); } else { // Default starts at 2 startP = 2; } // Call the platform-specific code for CPU count detection threadCount = GetOptimalThreadCount(); // Start the worker threads with this thread being the arbiter FindPrimes(threadCount, startP); // FindPrimes() only returns in the case of an error return -1; }
static double TimeFindPrimes( int nthread ) { Primes.clear(); tbb::task_scheduler_init init(nthread); tbb::tick_count t0 = tbb::tick_count::now(); tbb::parallel_for( tbb::blocked_range<Number>(0,1000000,500), FindPrimes() ); tbb::tick_count t1 = tbb::tick_count::now(); return (t1-t0).seconds(); }
int main(int argc, char **argv) { int start, end,i; //clock_t before, after; if( argc == 3 ) { CLstart = atoi(argv[1]); CLend = atoi(argv[2]); } else { printf("Uso:- %s <rango inicio> <rango fin>\n", argv[0]); exit(-1); } if (CLstart > CLend) { printf("Valor inicial debe ser menor o igual al valor final\n"); exit(-1); } if (CLstart < 1 && CLend < 2) { printf("El rango de busqueda debe estar formado por enteros positivos\n"); exit(-1); } start = CLstart; end = CLend; if (CLstart < 2) start = 2; if (start <= 2) globalPrimes[gPrimesFound++] = 2; if((start % 2) == 0 ) start = start + 1; // Asegurar que iniciamos con un numero impar long num_threads, end_num; for (num_threads = 2; num_threads < 10; num_threads += 2){ for(end_num = 10000000; end_num < 10000000*10; end_num *= 2){ start = 1; //end = end_num; omp_set_num_threads(num_threads); double t_start = omp_get_wtime(); FindPrimes(start, end_num); double t_end = omp_get_wtime(); printf("Primos=%d,Max=%d,Tiempo=%.2f,Hilos=%d\n", gPrimesFound, end_num, (t_end - t_start), num_threads); gPrimesFound = 0; } } }
int main(int argc, char **argv) { int start, end,i; clock_t before, after; int numThreads = 4; // Set number of threads. omp_set_num_threads(numThreads); if( argc == 3 ) { CLstart = atoi(argv[1]); CLend = atoi(argv[2]); } else { printf("Uso:- %s <rango inicio> <rango fin>\n", argv[0]); exit(-1); } if (CLstart > CLend) { printf("Valor inicial debe ser menor o igual al valor final\n"); exit(-1); } if (CLstart < 1 && CLend < 2) { printf("El rango de búsqueda debe estar formado por enteros positivos\n"); exit(-1); } start = CLstart; end = CLend; if (CLstart < 2) start = 2; if (start <= 2) globalPrimes[gPrimesFound++] = 2; if((start % 2) == 0 ) start = start + 1; // Asegurar que iniciamos con un número impar before = clock(); FindPrimes(start, end); after = clock(); printf("\n\nSe encontraron %8d primos entre %6d y %6d en %7.2f secs\n", gPrimesFound, CLstart, CLend, (float)(after - before)/ CLOCKS_PER_SEC); }