⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 is.c

📁 openmp版的banchmark
💻 C
📖 第 1 页 / 共 2 页
字号:
}/*****************************************************************//*************             R  A  N  K             ****************//*****************************************************************/void rank( int iteration ){    INT_TYPE    i, j, k;    INT_TYPE    l, m;    INT_TYPE    shift = MAX_KEY_LOG_2 - NUM_BUCKETS_LOG_2;    INT_TYPE    key;    INT_TYPE    min_key_val, max_key_val;    INT_TYPE	prv_buff1[MAX_KEY];#pragma omp master  {    key_array[iteration] = iteration;    key_array[iteration+MAX_ITERATIONS] = MAX_KEY - iteration;/*  Determine where the partial verify test keys are, load into  *//*  top of array bucket_size                                     */    for( i=0; i<TEST_ARRAY_SIZE; i++ )        partial_verify_vals[i] = key_array[test_index_array[i]];/*  Clear the work array */    for( i=0; i<MAX_KEY; i++ )        key_buff1[i] = 0;  }#pragma omp barrier    for (i=0; i<MAX_KEY; i++)      prv_buff1[i] = 0;/*  Copy keys into work array; keys in key_array will be reused each iter. */#pragma omp for nowait    for( i=0; i<NUM_KEYS; i++ ) {        key_buff2[i] = key_array[i];/*  Ranking of all keys occurs in this section:                 *//*  In this section, the keys themselves are used as their     own indexes to determine how many of each there are: their    individual population                                       */        prv_buff1[key_buff2[i]]++;  /* Now they have individual key   */    }                                       /* population                     */    for( i=0; i<MAX_KEY-1; i++ )           prv_buff1[i+1] += prv_buff1[i];  #pragma omp critical    {	for( i=0; i<MAX_KEY; i++ )	    key_buff1[i] += prv_buff1[i];    }/*  To obtain ranks of each key, successively add the individual key    population, not forgetting to add m, the total of lesser keys,    to the first key population                                          */#pragma omp barrier    #pragma omp master  {    /* This is the partial verify test section *//* Observe that test_rank_array vals are   *//* shifted differently for different cases */    for( i=0; i<TEST_ARRAY_SIZE; i++ )    {                                                     k = partial_verify_vals[i];          /* test vals were put here */        if( 0 <= k  &&  k <= NUM_KEYS-1 )            switch( CLASS )            {                case 'S':                    if( i <= 2 )                    {                        if( key_buff1[k-1] != test_rank_array[i]+iteration )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;                    }                    else                    {                        if( key_buff1[k-1] != test_rank_array[i]-iteration )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;                    }                    break;                case 'W':                    if( i < 2 )                    {                        if( key_buff1[k-1] !=                                           test_rank_array[i]+(iteration-2) )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;                    }                    else                    {                        if( key_buff1[k-1] != test_rank_array[i]-iteration )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;                    }                    break;                case 'A':                    if( i <= 2 )        	    {                        if( key_buff1[k-1] !=                                           test_rank_array[i]+(iteration-1) )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;        	    }                    else                    {                        if( key_buff1[k-1] !=                                           test_rank_array[i]-(iteration-1) )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;                    }                    break;                case 'B':                    if( i == 1 || i == 2 || i == 4 )        	    {                        if( key_buff1[k-1] != test_rank_array[i]+iteration )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;        	    }                    else                    {                        if( key_buff1[k-1] != test_rank_array[i]-iteration )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;                    }                    break;                case 'C':                    if( i <= 2 )        	    {                        if( key_buff1[k-1] != test_rank_array[i]+iteration )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;        	    }                    else                    {                        if( key_buff1[k-1] != test_rank_array[i]-iteration )                        {                            printf( "Failed partial verification: "                                  "iteration %d, test key %d\n",                                    iteration, i );                        }                        else                            passed_verification++;                    }                    break;            }            }/*  Make copies of rank info for use by full_verify: these variables    in rank are local; making them global slows down the code, probably    since they cannot be made register by compiler                        */    if( iteration == MAX_ITERATIONS )         key_buff_ptr_global = key_buff1;  } /* end master */}      /*****************************************************************//*************             M  A  I  N             ****************//*****************************************************************/main( argc, argv )    int argc;    char **argv;{    int             i, iteration, itemp;    int		    nthreads = 1;    double          timecounter, maxtime;/*  Initialize the verification arrays if a valid class */    for( i=0; i<TEST_ARRAY_SIZE; i++ )        switch( CLASS )        {            case 'S':                test_index_array[i] = S_test_index_array[i];                test_rank_array[i]  = S_test_rank_array[i];                break;            case 'A':                test_index_array[i] = A_test_index_array[i];                test_rank_array[i]  = A_test_rank_array[i];                break;            case 'W':                test_index_array[i] = W_test_index_array[i];                test_rank_array[i]  = W_test_rank_array[i];                break;            case 'B':                test_index_array[i] = B_test_index_array[i];                test_rank_array[i]  = B_test_rank_array[i];                break;            case 'C':                test_index_array[i] = C_test_index_array[i];                test_rank_array[i]  = C_test_rank_array[i];                break;        };        /*  Printout initial NPB info */    printf( "\n\n NAS Parallel Benchmarks 2.3 OpenMP C version"	    " - IS Benchmark\n\n" );    printf( " Size:  %d  (class %c)\n", TOTAL_KEYS, CLASS );    printf( " Iterations:   %d\n", MAX_ITERATIONS );/*  Initialize timer  */                 timer_clear( 0 );/*  Generate random number sequence and subsequent keys on all procs */    create_seq( 314159265.00,                    /* Random number gen seed */                1220703125.00 );                 /* Random number gen mult *//*  Do one interation for free (i.e., untimed) to guarantee initialization of      all data and code pages and respective tables */#pragma omp parallel        rank( 1 );  /*  Start verification counter */    passed_verification = 0;    if( CLASS != 'S' ) printf( "\n   iteration\n" );/*  Start timer  */                 timer_start( 0 );/*  This is the main iteration */    #pragma omp parallel private(iteration)        for( iteration=1; iteration<=MAX_ITERATIONS; iteration++ )    {#pragma omp master	        if( CLASS != 'S' ) printf( "        %d\n", iteration );	        rank( iteration );	#if defined(_OPENMP)	#pragma omp master	nthreads = omp_get_num_threads();#endif /* _OPENMP */	    }/*  End of timing, obtain maximum time of all processors */    timer_stop( 0 );    timecounter = timer_read( 0 );/*  This tests that keys are in sequence: sorting of last ranked key seq    occurs here, but is an untimed operation                             */    full_verify();/*  The final printout  */    if( passed_verification != 5*MAX_ITERATIONS + 1 )        passed_verification = 0;    c_print_results( "IS",                     CLASS,                     TOTAL_KEYS,                     0,                     0,                     MAX_ITERATIONS,		     nthreads,                     timecounter,                     ((double) (MAX_ITERATIONS*TOTAL_KEYS))                                                  /timecounter/1000000.,                     "keys ranked",                      passed_verification,                     NPBVERSION,                     COMPILETIME,                     CC,                     CLINK,                     C_LIB,                     C_INC,                     CFLAGS,                     CLINKFLAGS,		     "randlc");         /**************************/}        /*  E N D  P R O G R A M  */         /**************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -