view example/Prime/ppe/Prime.cc @ 1262:4e6a6e620fc4 draft

modify
author Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
date Sat, 19 Nov 2011 14:29:51 +0900
parents bb9c885c1cb5
children
line wrap: on
line source

#include <stdio.h>
#include <math.h>
#include "SchedTask.h"
#include "Prime.h"
#include "Func.h"

SchedDefineTask1(Prime, prime);

	static int
prime(SchedTask *smanager, void *rbuf, void *wbuf)
{
	long start = (long)smanager->get_param(0);	/* 素数判定の開始地点 */
	long end   = (long)smanager->get_param(1);	/* 素数判定の終了地点 */
	long range = end - start;					/* 判定する範囲		  */

	/* 判定結果を収める配列を受け取る */
	bool *output = (bool*)smanager->get_output(wbuf, 0);

	/* 初期化 */
	for (int i = 0; i < range; i++){
		output[i] = true;
	}



	for (long i = start, index = 0; i < end; i++, index++) {
		long limit = (long)sqrt((double) i);		/* 割る数の最大値を求める */
		for (long j = 2; j <= limit; j++) {
			/* 割り切れた場合、0を代入し素数じゃないという判定を下す */
			if (i % j == 0) {
				output[index] = false;
				break;
			}
		}
	}
	return 0;
}