comparison example/fileread/main.cc @ 1827:d1212026e2a0 draft

some fix
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Tue, 17 Dec 2013 13:57:34 +0900
parents 82c2b9eec625
children f0dab5fffe7a
comparison
equal deleted inserted replaced
1826:d3a9772074d6 1827:d1212026e2a0
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <string.h> 3 #include <string.h>
4 #include <sys/stat.h> 4 #include <sys/stat.h>
5 #include <sys/time.h> 5 #include <sys/time.h>
6 #include "TaskManager.h" 6 #include "TaskManager.h"
7 #include "SchedTask.h"
7 #include "Func.h" 8 #include "Func.h"
8 9
9 extern void task_init(void); 10 extern void task_init(void);
10 11
11 static double st_time; 12 static double st_time;
18 const char *usr_help_str = "Usage: ./fileread [-cpu cpu_num] [-file filename]\n\ 19 const char *usr_help_str = "Usage: ./fileread [-cpu cpu_num] [-file filename]\n\
19 -cpu Number of SPE (default 1) \n\ 20 -cpu Number of SPE (default 1) \n\
20 -file Opne file\n"; 21 -file Opne file\n";
21 typedef struct fileread { 22 typedef struct fileread {
22 struct filesize *self; 23 struct filesize *self;
23 int fd; 24 int *fd;
24 long division_size; 25 long division_size;
25 long task_number; 26 long task_number;
26 long task_num; 27 long task_num;
27 long filesize; 28 long filesize;
28 long left_size; 29 long left_size;
31 } Fileread, *FilereadPtr; 32 } Fileread, *FilereadPtr;
32 33
33 SchedDefineTask1(RUN_BLOCKS,run16); 34 SchedDefineTask1(RUN_BLOCKS,run16);
34 35
35 static int 36 static int
36 run16(SchedTask *m, void *in, void *out) { 37 run16(SchedTask *manager, void *in, void *out) {
37 38
38 FilereadPtr fr = (FilereadPtr)in; 39 FilereadPtr fr = (FilereadPtr)in;
39 HTaskPtr wait; 40 HTaskPtr wait;
40 41
41 for (int task_number = 0; fr->left_size > 0 && task_number < fr->task_blocks; task_number++) { 42 for (int i = 0; (fr->left_size > 0) && (i < fr->task_blocks); i++) {
42 HTaskPtr read = manager->create_task(Read_task); 43 HTaskPtr read = manager->create_task(Read_task);
43 read->set_cpu(fr->cpu); 44 read->set_cpu(fr->cpu);
44 45
45 if (task_number == fr->task_blocks / 2) wait = read; 46 if (fr->task_number == fr->task_blocks / 2) wait = read;
46 47
47 //ファイルディスクリプタをそのままタスクに渡してあげる 48 //ファイルディスクリプタをそのままタスクに渡してあげる
49 read->set_inData(0,fr->fd,sizeof(int*));
48 50
49 read->set_param(0,(long)fr->task_number); //生成するTaskが何番目か 51 read->set_param(0,(long)fr->task_number); //生成するTaskが何番目か
50 read->set_param(1,(long)fr->division_size); //1つのタスクが読み込む量 52 read->set_param(1,(long)fr->division_size); //1つのタスクが読み込む量
51 if(fr->left_size <= fr->division_size){ 53 if(fr->left_size <= fr->division_size){
52 read->set_param(2,(long)fr->left_size); 54 read->set_param(2,(long)fr->left_size);
53 }else{ 55 }else{
54 read->set_param(2,(long)fr->division_size); 56 read->set_param(2,(long)fr->division_size);
55 } 57 }
56 read->set_param(3,(long)fr->fd);
57 read->spawn(); 58 read->spawn();
58 59
59 fr->left_size -= fr->division_size; 60 fr->left_size -= fr->division_size;
61 fr->task_number++;
60 } 62 }
61 63
62 if (fr->left_size > 0) { 64 if (fr->left_size > 0) {
63 HTaskPtr next = manager->create_task(RUN_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0); 65 HTaskPtr next = manager->create_task(RUN_BLOCKS, (memaddr)&fr->self, sizeof(memaddr),0,0);
64 next->wait_for(wait); 66 next->wait_for(wait);
105 } 107 }
106 108
107 static void 109 static void
108 run_start(TaskManager *manager,char *filename) 110 run_start(TaskManager *manager,char *filename)
109 { 111 {
110 int fd; 112 int *fd = (int*)manager->allocate(sizeof(int));
111
112 struct stat *sb = (struct stat*)manager->allocate(sizeof(struct stat)); 113 struct stat *sb = (struct stat*)manager->allocate(sizeof(struct stat));
113 114
114 if ((fd=open(filename,O_RDONLY,0666))==0) { 115 if ((*fd=open(filename,O_RDONLY,0666))==0) {
115 fprintf(stderr,"can't open %s\n",filename); 116 fprintf(stderr,"can't open %s\n",filename);
116 } 117 }
117 118
118 if (fstat(fd,sb)) { 119 if (fstat(*fd,sb)) {
119 fprintf(stderr,"can't fstat %s\n",filename); 120 fprintf(stderr,"can't fstat %s\n",filename);
120 } 121 }
121 122
122 FilereadPtr fr = (FilereadPtr)manager->allocate(sizeof(Fileread)); 123 FilereadPtr fr = (FilereadPtr)manager->allocate(sizeof(Fileread));
123 124
124 fr->cpu = spe_cpu; 125 fr->fd = fd;
126 fr->cpu = spe_cpu;
125 fr->task_blocks = 16; 127 fr->task_blocks = 16;
126 fr->filesize = sb->st_size; 128 fr->filesize = sb->st_size;
127 fr->left_size = fr->filesize; 129 fr->left_size = fr->filesize;
128 fr->division_size = DIVISION_SIZE; 130 fr->division_size = DIVISION_SIZE;
129 fr->task_num = fr->filesize / DIVISION_SIZE; 131 fr->task_num = fr->filesize / DIVISION_SIZE;