changeset 1800:9a1ba9cb9557 draft

add file
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Fri, 06 Dec 2013 05:31:30 +0900
parents d9122ca02431
children e91bf033443a fa15a19d27ef
files example/word_count/ppe/Exec_Data_Parallel.cc
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/word_count/ppe/Exec_Data_Parallel.cc	Fri Dec 06 05:31:30 2013 +0900
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <string.h>
+#include "Exec.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask1(Exec_Data_Prallel,wordcount);
+
+static int
+wordcount(SchedTask *s, void *rbuf, void *wbuf)
+{
+    long task_spwaned = (long)s->get_param(0);
+    long division_size = (long)s->get_param(1);
+    long length = (long)s->get_param(2);
+    long out_size = (long)s->get_param(3);
+
+    long allocation = task_spwaned + (long)s->x;
+    
+    char *i_data = (char *)rbuf + allocation*division_size;
+    unsigned long long *o_data = (unsigned long long*)wbuf + allocation*out_size;
+    unsigned long long *head_tail_flag = o_data +2;
+    int word_flag = 0;
+    int word_num = 0;
+    int line_num = 0;
+    int i = 0;
+    
+    head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A);
+    word_num -= 1-head_tail_flag[0];
+
+    for (; i < length; i++) {
+        if (i_data[i] == 0x20) { // 空白
+            word_flag = 1;
+        } else if (i_data[i] == 0x0A) { // 改行
+            line_num += 1;
+            word_flag = 1;
+        } else {
+            word_num += word_flag;
+            word_flag = 0;
+        }
+    }
+
+    word_num += word_flag;
+    head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A);
+
+    // s->printf("SPE word %d line %d\n",word_num,line_num);
+
+    o_data[0] = (unsigned long long)word_num;
+    o_data[1] = (unsigned long long)line_num;
+
+    return 0;
+}