Mercurial > hg > Game > Cerium
changeset 1244:cd50c48f45e7 draft real_matrix
fix
author | Daichi Toma <amothic@gmail.com> |
---|---|
date | Thu, 03 Nov 2011 20:40:17 +0900 |
parents | 9df036b11eae |
children | a97b4dd4574c 163207b736c5 |
files | example/Miller_Rabin/main.cc example/Miller_Rabin/ppe/Prime.cc example/Miller_Rabin/ppe/PrintTask.cc example/Miller_Rabin/spe/Prime.cc example/Miller_Rabin/spe/PrintTask.cc |
diffstat | 5 files changed, 20 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/example/Miller_Rabin/main.cc Tue Nov 01 19:23:11 2011 +0900 +++ b/example/Miller_Rabin/main.cc Thu Nov 03 20:40:17 2011 +0900 @@ -39,9 +39,9 @@ { U64 div_size = 1000; - U64 task_num = ((num >> 1) + div_size - 1) / div_size; + U64 task_num = (num + div_size - 1) / div_size; - bool *output = (bool*)manager->allocate(sizeof(bool)*task_num*div_size); /* 判定結果を収める配列 */ + bool *output = (bool*)manager->allocate(sizeof(bool)*(task_num*div_size >> 1)); /* 判定結果を収める配列 */ HTask *print = manager->create_task(PrintTask); @@ -49,12 +49,12 @@ HTask *prime = manager->create_task(Prime); - prime->set_outData(0,&output[i*div_size],sizeof(bool)*div_size); + 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 - 1)); // 終了地点 + prime->set_param(1,(memaddr)((i+1)*div_size)); // 終了地点 print->wait_for(prime);
--- a/example/Miller_Rabin/ppe/Prime.cc Tue Nov 01 19:23:11 2011 +0900 +++ b/example/Miller_Rabin/ppe/Prime.cc Thu Nov 03 20:40:17 2011 +0900 @@ -62,18 +62,19 @@ U64 start = (U64)smanager->get_param(0); /* 素数判定の開始地点 */ U64 end = (U64)smanager->get_param(1); /* 素数判定の終了地点 */ U64 range = end - start; /* 判定する範囲 */ + U64 index_range = range >> 1; /* 判定結果を収める配列を受け取る */ bool *output = (bool*)smanager->get_output(wbuf, 0); /* 初期化 */ - for (U64 i = 0; i < range; i++){ - output[i] = true; + for (U64 i = 0; i < index_range; i++){ + output[i] = false; } - for (U64 i = start + 1,index = 0; index < range; i += 2, index++) { - if (!isPrime(i)) { - output[index] = false; + for (U64 i = start + 1,index = 0; i < end ; i += 2, index++) { + if (isPrime(i)) { + output[index] = true; } } return 0;
--- a/example/Miller_Rabin/ppe/PrintTask.cc Tue Nov 01 19:23:11 2011 +0900 +++ b/example/Miller_Rabin/ppe/PrintTask.cc Thu Nov 03 20:40:17 2011 +0900 @@ -19,14 +19,13 @@ U64 size = ((U64)smanager->get_param(0)) >> 1; /* 出力する範囲 */ bool *input = (bool*)smanager->get_input(rbuf, 0); /* 出力する配列 */ - printf("%d ",(int)2); + printf("%d\n",(int)2); /* 素数の判定結果が1ならば出力する */ for (U64 i = 1; i < size; i++) { if ( input[i] == true ) { - printf("%llu ",i*2+1); + printf("%llu\n",i*2+1); } } - printf("\n"); return 0; }
--- a/example/Miller_Rabin/spe/Prime.cc Tue Nov 01 19:23:11 2011 +0900 +++ b/example/Miller_Rabin/spe/Prime.cc Thu Nov 03 20:40:17 2011 +0900 @@ -62,18 +62,19 @@ U64 start = (U64)smanager->get_param(0); /* 素数判定の開始地点 */ U64 end = (U64)smanager->get_param(1); /* 素数判定の終了地点 */ U64 range = end - start; /* 判定する範囲 */ + U64 index_range = range >> 1; /* 判定結果を収める配列を受け取る */ bool *output = (bool*)smanager->get_output(wbuf, 0); /* 初期化 */ - for (U64 i = 0; i < range; i++){ - output[i] = true; + for (U64 i = 0; i < index_range; i++){ + output[i] = false; } - for (U64 i = start + 1,index = 0; index < range; i += 2, index++) { - if (!isPrime(i)) { - output[index] = false; + for (U64 i = start + 1,index = 0; i < end ; i += 2, index++) { + if (isPrime(i)) { + output[index] = true; } } return 0;
--- a/example/Miller_Rabin/spe/PrintTask.cc Tue Nov 01 19:23:11 2011 +0900 +++ b/example/Miller_Rabin/spe/PrintTask.cc Thu Nov 03 20:40:17 2011 +0900 @@ -19,14 +19,13 @@ U64 size = ((U64)smanager->get_param(0)) >> 1; /* 出力する範囲 */ bool *input = (bool*)smanager->get_input(rbuf, 0); /* 出力する配列 */ - printf("%d ",(int)2); + printf("%d\n",(int)2); /* 素数の判定結果が1ならば出力する */ for (U64 i = 1; i < size; i++) { if ( input[i] == true ) { - printf("%llu ",i*2+1); + printf("%llu\n",i*2+1); } } - printf("\n"); return 0; }