changeset 23:5d09235f2a7c

check types size
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Mon, 03 Feb 2014 20:27:57 +0900
parents 508b47c8f4d8
children a8d237e822a8
files c/long_size/Makefile c/long_size/README c/long_size/main.cc c/long_size/read.h parallel_processing/chapter4/ppb_prime_result_parallel/Makefile parallel_processing/chapter4/ppb_prime_result_parallel/ppb_prime_result_parallel.cc
diffstat 6 files changed, 105 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/c/long_size/Makefile	Mon Feb 03 20:27:57 2014 +0900
@@ -0,0 +1,10 @@
+TARGET=long_size
+OPTION= -Wall -O0 -g
+
+$(TARGET):main.cc
+	clang $(OPTION) -o $(TARGET) main.cc
+
+clean:
+	rm -f $(TARGET)
+	rm -r $(TARGET).dSYM
+	rm -f *~ \#*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/c/long_size/README	Mon Feb 03 20:27:57 2014 +0900
@@ -0,0 +1,9 @@
+(2013.11.11)
+一括readと分割readの時間比較のためのプログラム
+
+"Usage : ./read_lseek [-file filename] [-b -d]"
+
+-b bulk read(一括read)
+-d divide read(分割read)
+
+ONE_TASK_READ_SIZE にて分割サイズを変更できる。
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/c/long_size/main.cc	Mon Feb 03 20:27:57 2014 +0900
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include <limits.h>
+
+int main(void){
+    printf("int  MAX  : %d\n",INT_MAX);
+    printf("long size : %d\n",LONG_BIT);
+    printf("long MAX  : %ld\n",LONG_MAX);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/c/long_size/read.h	Mon Feb 03 20:27:57 2014 +0900
@@ -0,0 +1,6 @@
+typedef struct read{
+    int fd;
+    unsigned long int text_size;
+    int one_task_read_size;
+    int task_num;
+} read_t;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/parallel_processing/chapter4/ppb_prime_result_parallel/Makefile	Mon Feb 03 20:27:57 2014 +0900
@@ -0,0 +1,11 @@
+TARGET = ppb_prime_result_parallel
+CC = clang++
+CPPFLAGS = -g -O0
+
+$(TARGET): $(TARGET).o
+	$(CC) -g -O0 -o $@ $<
+$(TARGET).o: $(TARGET).cc
+
+clean:
+	rm -f $(TARGET)
+	rm -f *.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/parallel_processing/chapter4/ppb_prime_result_parallel/ppb_prime_result_parallel.cc	Mon Feb 03 20:27:57 2014 +0900
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <math.h>
+#include <pthread.h>
+
+#define THREAD_NUM 3
+#define DATA_NUM 100
+
+typedef struct _thread_arg {
+    int id;
+    bool *primes;
+} thread_arg_t;
+
+void *
+thread_func(void *arg)
+{
+    thread_arg_t *targ = (thread_arg_t *)arg;
+
+    int range = (DATA_NUM - 2) / THREAD_NUM + 1;
+    int c_start = 2 + targ->id * range;
+    int c_end = 2 + (targ->id + 1) * range;
+    if (c_end > DATA_NUM) c_end = DATA_NUM;
+
+    for (int i = c_start; i < c_end; i++) {
+        int limit = (int)sqrt((double) i);
+        for (int j = 2; j <= limit; j++) {
+            if (targ->primes[j] && i % j == 0){
+                targ->primes[i] = false;
+                break;
+            }
+        }
+    }
+    return 0;
+}
+
+int
+main()
+{
+    pthread_t handle[THREAD_NUM];
+    thread_arg_t targ[THREAD_NUM];
+    bool primes[DATA_NUM];
+
+    /* initialize */
+    for (int i = 0; i < DATA_NUM; i++) primes[i] = true;
+
+    for (int i = 0; i < THREAD_NUM; i++) {
+        targ[i].id = i;
+        targ[i].primes = primes;
+        pthread_create(&handle[i], NULL,&thread_func, (void*)&targ[i]);
+    }
+
+    /* wait for running all thread */
+    for (int i = 0; i < THREAD_NUM; i++) pthread_join(handle[i], NULL);
+
+    for (int i = 2; i < DATA_NUM; i++)
+        if (primes[i]) printf("%d ", i);
+    printf("\n");
+
+    return 0;
+}