home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / test / io / buffer / mt_test1.c < prev    next >
C/C++ Source or Header  |  2006-10-18  |  3KB  |  145 lines

  1. /* In this test, we use multiple threads to work on a 
  2.  * a same file.
  3.  */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <pthread.h>
  7.  
  8. #include "ncac-interface.h"
  9. #include "internal.h"
  10.  
  11. #include "trove.h"
  12.  
  13. #include "trove-init.c"
  14. #include "pvfs2-internal.h"
  15.  
  16. TROVE_coll_id coll_id;
  17. TROVE_handle file_handle;
  18. TROVE_context_id trove_context;
  19.  
  20. void do_io_read(int *myid);
  21.  
  22. int main(int argc, char * argv[])
  23. {
  24.     NCAC_info_t info;
  25.  
  26.     int ret1, ret2, ret3;
  27.  
  28.     pthread_t thread1, thread2, thread3;
  29.  
  30.  
  31.  
  32.     trove_init( &coll_id, &file_handle, &trove_context );
  33.  
  34.     info.max_req_num = 1000;
  35.     info.extsize     = 32768;
  36.     info.cachesize   = 1048576;
  37.  
  38.  
  39.     cache_init(&info);
  40.    
  41.     if (pthread_create(&thread1,
  42.                  NULL,
  43.                  (void *) do_io_read,
  44.                  (void *) &ret1) != 0)
  45.         perror("pthread_create"), exit(1);
  46.  
  47.     if (pthread_create(&thread2,
  48.                  NULL,
  49.                  (void *) do_io_read,
  50.                  (void *) &ret2) != 0)
  51.         perror("pthread_create"), exit(1);
  52.  
  53.     if (pthread_create(&thread3,
  54.                  NULL,
  55.                  (void *) do_io_read,
  56.                  (void *) &ret3) != 0)
  57.         perror("pthread_create"), exit(1);
  58.  
  59.     if (pthread_join(thread1, NULL) != 0)
  60.         perror("pthread_join"),exit(1);
  61.  
  62.     if (pthread_join(thread2, NULL) != 0)
  63.         perror("pthread_join"),exit(1);
  64.  
  65.     if (pthread_join(thread3, NULL) != 0)
  66.         perror("pthread_join"),exit(1);
  67.  
  68.     trove_close_context(coll_id, trove_context);
  69.     trove_finalize(TROVE_METHOD_DBPF);
  70.  
  71.     //cache_dump_active_list();
  72.     //cache_dump_inactive_list();
  73.  
  74.     return 0;
  75. }
  76.  
  77. void do_io_read(int *result)
  78. {
  79.     PVFS_offset offarr[100];
  80.     PVFS_size sizearr[100];
  81.  
  82.     cache_read_desc_t desc;
  83.     cache_request_t request[100];
  84.     cache_reply_t reply[100];
  85.  
  86.     int flag;
  87.     int ret;
  88.     int i;
  89.     int loop=10;
  90.  
  91.     int ncnt;
  92.  
  93.     desc.coll_id     = coll_id;
  94.     desc.handle     = file_handle;
  95.     desc.context_id     = trove_context;
  96.  
  97.     desc.buffer = 0;
  98.     desc.len    = 0;
  99.  
  100.     desc.stream_array_count=1;
  101.     desc.stream_offset_array = offarr;
  102.     desc.stream_size_array = sizearr;
  103.  
  104.     for ( i = 0; i< loop; i++ ) {
  105.         offarr[0] = i*65536+1024;
  106.         sizearr[0] = 32768;
  107.     
  108.         ret = cache_read_post(&desc, &request[0], &reply[0], NULL);
  109.         if (ret<0){
  110.             fprintf(stderr, "cache_read_post error\n");
  111.         }else{
  112.             fprintf(stderr, "cache_read_post ok: status: %d, cbufcnt=%d\n", request[0].status, reply[0].count);
  113.         }
  114.  
  115.  
  116.         while ( 1 ){
  117.             ret = cache_req_test(&request[0], &flag, &reply[0], NULL);
  118.             if (ret<0){
  119.                 fprintf(stderr, "cache_req_test error\n");
  120.             }else{
  121.                 if (flag){
  122.                     fprintf(stderr, "cache_req_test ok: flag=%d, status: %d, cbufcnt=%d\n", flag, request[0].status, reply[0].count);
  123.                     for ( ncnt=0; ncnt < reply[0].count; ncnt ++ ) {
  124.                         fprintf(stderr, "[%d] %p len:%lld\n", ncnt,
  125.                                     reply[0].cbuf_offset_array[ncnt], 
  126.                                     lld(reply[0].cbuf_size_array[ncnt]));
  127.                     }    
  128.                     break;        
  129.                 }
  130.             }
  131.         }
  132.  
  133.         if (flag){
  134.             ret = cache_req_done(&request[0]);
  135.             if (ret<0){
  136.                 fprintf(stderr, "cache_req_done error\n");
  137.             }else
  138.                 fprintf(stderr, "cache_req_done ok---\n");
  139.         }
  140.     }
  141.  
  142.     *result = ret;
  143.  
  144. }
  145.