Changeset 626 for trunk/user/pgcd


Ignore:
Timestamp:
Apr 29, 2019, 7:25:09 PM (6 years ago)
Author:
alain
Message:

This version has been tested on the sort multithreaded application
for TSAR_IOB architectures ranging from 1 to 8 clusters.
It fixes three bigs bugs:
1) the dev_ioc device API has been modified: the dev_ioc_sync_read()
and dev_ioc_sync_write() function use now extended pointers on the
kernel buffer to access a mapper stored in any cluster.
2) the hal_uspace API has been modified: the hal_copy_to_uspace()
and hal_copy_from_uspace() functions use now a (cxy,ptr) couple
to identify the target buffer (equivalent to an extended pointer.
3) an implementation bug has been fixed in the assembly code contained
in the hal_copy_to_uspace() and hal_copy_from_uspace() functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/pgcd/pgcd.c

    r625 r626  
    1212#include <almosmkh.h>
    1313
     14#define   INSTRUMENTATION  0
     15#define   IDBG             0
     16
    1417/////////////////
    1518void main( void )
     
    1720    int                opx;
    1821    int                opy;
     22    int                x;
     23    int                y;
    1924    unsigned long long cycle;
    2025    unsigned int       cxy;
     
    2429    get_core( &cxy , &lid );
    2530
    26     printf( "\n\n[pgcd] starts on core[%x,%d] / cycle %d\n",
     31    printf( "\n[pgcd] starts on core[%x,%d] / cycle %d\n\n",
    2732    cxy , lid , (unsigned int)cycle );
    2833
    29     while (1)
     34    // get operand X
     35    printf("operand X = ");
     36    opx = get_uint32();
     37    printf("\n");
     38
     39    // get operand Y
     40    printf("operand Y = ");
     41    opy = get_uint32();
     42    printf("\n");
     43
     44    // check operands
     45    if( (opx == 0) || (opy == 0) )
    3046    {
    31         printf("\n*******************\n");
    32         printf("operand X = ");
    33         opx = get_uint32();
    34         printf("\n");
    35         printf("operand Y = ");
    36         opy = get_uint32();
    37         printf("\n");
     47        printf("\n[pgcd error] operands must be strictly positive\n");
     48        exit(0);
     49    }
    3850
    39         if( (opx == 0) || (opy == 0) )
    40         {
    41            printf("operands must be positive and larger than 0 => exit\n");
    42            exit( 0 );
    43         }
    44         else
    45         {
    46             while (opx != opy)
    47             {
    48                 if(opx > opy)   opx = opx - opy;
    49                 else            opy = opy - opx;
    50             }
    51             printf("pgcd      = %d", opx);
    52         }
     51    // compute PGCD
     52    x = opx;
     53    y = opy;
     54    while (x != y)
     55    {
     56        if(x > y)   x = x - y;
     57        else        y = y - x;
    5358    }
     59
     60    // display result
     61    printf("pgcd      = %d\n", x);
     62
     63#if INSTRUMENTATION
     64
     65    char   name[64];
     66    char   path[128];
     67
     68    // build a file name from X and Y values
     69    snprintf( name , 64 , "pgcd_%d_%d", opx, opy );
     70
     71    // build file pathname
     72    snprintf( path , 128 , "home/%s" , name );
     73
     74#if IDBG
     75idbg();
     76#endif
     77
     78    // open file
     79    FILE * stream = fopen( path , NULL );
     80
     81    if( stream == NULL )
     82    {
     83        printf("\n[pgcd error] cannot open instrumentation file <%s>\n", name );
     84        exit(0);
     85    }
     86
     87    printf("\n[pgcd] file %s successfully open\n", path);
     88
     89#if IDBG
     90idbg();
     91#endif
     92
     93    // register results to file
     94    int ret = fprintf( stream , "pgcd( %d , %d ) = %d\n", opx, opy, x );
     95
     96    if( ret < 0 )
     97    {
     98        printf("\n[pgcd error] cannot write to instrumentation file <%s>\n", name );
     99        exit(0);
     100    }
     101
     102    printf("\n[pgcd] file %s successfully written\n", path);
     103
     104    display_mapper( path , 0 , 64 );
     105
     106    // close instrumentation file
     107
     108#if IDBG
     109idbg();
     110#endif
     111
     112    if( fclose( stream ) )
     113    {
     114        printf("\n[pgcd error] cannot close the file <%s>\n", name );
     115        exit(0);
     116    }
     117
     118    printf("\n[pgcd] file %s successfully closed\n", path);
     119
     120#endif
     121
     122    exit(0);
     123       
    54124} // end pgcd
    55125
Note: See TracChangeset for help on using the changeset viewer.