/////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2006 Intel Corporation // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither name of Intel Corporation nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////// // This code is for Chapter 7 // Reference to Figures 7.16, 7.17 and 7.19 // // For compilation, using Intel compiler // User must install Intel compiler, before running this code // // Possible compilation instruction: // // Windows: icl /O2 /Qopenmp -o sieve sieve.cpp // Linux: icc -O2 -openmp -o sieve sieve.cpp // // Note: There is a Makefile in this package as well // #include #include #include #include #include #include using namespace std; #include "Figure_7.16" #include "Figure_7.17" #include "Figure_7.19" long TimeSieve( long (*f)( long ), const char* name, long n, long trials ) { clock_t t0 = clock(); long result = 0; for( long k=0; k3 ) { printf("usage: %s n trials\n", argv[0]); exit(1); } long n = argc>1 ? strtol( argv[1], 0, 0 ) : 100000000; long trials = argc>2 ? strtol( argv[2], 0, 0 ) : 1; printf("%20s %9s%9s %s\n","Routine","n","result","seconds"); long result0 = TimeSieve( CacheUnfriendlySieve, "CacheUnfriendlySieve", n, trials ); long result1 = TimeSieve( CacheFriendlySieve, "CacheFriendlySieve", n, trials ); long result2 = TimeSieve( ParallelSieve, "ParallelSieve", n, trials ); if( result0!=result1 || result1!=result2 ) { printf("ERROR: result0=%ld result1=%ld result2=%ld\n",result0,result1,result2); } return 0; };