Mercurial > hg > Game > Cerium
view example/Miller_Rabin/main.cc @ 2069:26aa08c9a1de draft default tip
cuda example fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 12 Feb 2017 10:04:55 +0900 |
parents | 4e8c53b4c52a |
children |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "TaskManager.h" #include "Func.h" typedef unsigned long long U64; /* task_initを宣言 */ extern void task_init(void); /* TaskManagerを宣言 */ extern TaskManager *manager; static U64 num = 1000; static bool print_flag = false; /* help文章 */ const char *usr_help_str = "Usage: ./prime [-cpu spe_num] [-num N]\n\ -cpu Number of SPE (default 1) \n\ -num Caluculate of Prime scope (default 1000 * 1000 * 1000) "; int init(int argc, char **argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-num") == 0) { num = atoi(argv[++i]); } else if (strcmp(argv[i], "-print") == 0) { print_flag = true; } } return 0; } void prime_init(TaskManager *manager) { U64 div_size = 256; U64 task_num = (num + div_size - 1) / div_size; bool *output = (bool*)manager->allocate(sizeof(bool)*(task_num*div_size >> 1)); /* 判定結果を収める配列 */ HTask *print = manager->create_task(PrintTask); for (U64 i = 0; i < task_num; i++) { HTask *prime = manager->create_task(Prime); prime->set_outData(0,&output[i*div_size>>1],sizeof(bool)*div_size>>1); prime->set_cpu(SPE_ANY); prime->set_param(0,(memaddr)(i*div_size)); // 開始地点 prime->set_param(1,(memaddr)((i+1)*div_size)); // 終了地点 print->wait_for(prime); prime->spawn(); } /* 出力用のタスクに判定結果を収めた配列を渡す */ print->set_inData(0,output,sizeof(bool)*(task_num*div_size >> 1)); /* 出力する数を渡す */ print->set_param(0,(memaddr)num); /* printするかどうかを渡す */ print->set_param(1,(memaddr)print_flag); /* PPEを使うように指示 */ print->set_cpu(CPU_PPE); /* タスクを登録 */ print->spawn(); } int TMmain(TaskManager *manager, int argc, char *argv[]) { if (init(argc, argv) < 0) { return -1; } task_init(); prime_init(manager); return 0; }