Changeset 100

Show
Ignore:
Timestamp:
03/18/07 04:53:47
Author:
kunxi
Message:

Add validation for io_fread_shared_comm

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/io_fread_shared_comm.upc

    r86 r100  
    77 
    88/* For all BLOCKSIZE == 0, use the static memeory. 
    9 for all other cases, use the dynamic memory allocation 
    10 */ 
     9 * for all other cases, use the dynamic memory allocation 
     10 */ 
    1111 
    1212#if BLOCKSIZE == 0 
     
    1818         
    1919        int i; 
    20         int num = 24; 
    21         int offset = 6; 
     20        int nmemb = 24; 
    2221        int blocksize = BLOCKSIZE; 
     22        int memoff = 6; 
     23        upc_off_t fileoff = 19; 
    2324        ssize_t bytes; 
    24         upc_off_t vo; 
     25        upc_off_t offset; 
     26 
     27        if (argc != 2) { 
     28                if (MYTHREAD == 0) 
     29                        printf("Usage: %s file\n", argv[0]); 
     30                upc_global_exit(-1); 
     31        } 
    2532 
    2633#if BLOCKSIZE != 0 
     
    3239#if BLOCKSIZE != 0 
    3340                if (MYTHREAD == 0) 
    34                 upc_free(buffer); 
     41                       upc_free(buffer); 
    3542#endif 
    3643                GULA_FAIL("failed to open the file using UPC_RDONLY | UPC_COMMON_FP"); 
    3744        } 
     45        upc_barrier; 
    3846 
     47        upc_all_fseek(fd, fileoff * sizeof(TYPE), UPC_SEEK_SET); 
     48        bytes = upc_all_fread_shared(fd, buffer + memoff, blocksize, sizeof(TYPE), nmemb, UPC_IN_NOSYNC | UPC_OUT_NOSYNC); 
    3949 
    4050        upc_barrier; 
    41  
    42         upc_all_fseek(fd, 19*sizeof(int), UPC_SEEK_SET); 
    43         bytes = upc_all_fread_shared(fd, buffer+offset, blocksize, sizeof(TYPE), num, UPC_IN_NOSYNC | UPC_OUT_NOSYNC); 
    44  
    45         upc_barrier; 
     51         
     52        /* Validation for data integrity */ 
    4653        if( MYTHREAD == 0 ) { 
    47         for(i = 0; i < num; i++ ) 
    48                 fprintf( stderr, "%u ", buffer[i+offset] ); 
     54                for (i = 0; i < nmemb; i++) { 
     55                        if (buffer[memoff + i] != (fileoff + i) % 0x80) 
     56                                GULA_FAIL("Data integrity is violated!"); 
     57                } 
    4958        } 
    5059 
    51         vo = upc_all_fseek(fd, 0, UPC_SEEK_CUR); 
    52         fprintf(stderr, "th%d: orign=%d, read %d bytes, offset = %d \n", MYTHREAD, 19*sizeof(int), bytes, vo); 
    53         upc_barrier
     60        offset = upc_all_fseek(fd, 0, UPC_SEEK_CUR); 
     61        if (offset != (fileoff + nmemb) * sizeof(TYPE)) 
     62               GULA_FAIL("Fail to setup the file pointer")
    5463 
    5564#if BLOCKSIZE != 0