Beispiel #1
0
int main(int ac, char **av){
  struct timeval s,t;
  double startTime, endTime;

  if(ac != 2){
    printf("引数は分割する分の数を指定して下さい。\n");
    exit(1);
  }
    
  long double SUM=0.0L;
  double X;
  double Y;
  int N = atoi(av[1]);
  
  srand((unsigned)time(NULL));
  gettimeofday(&s, NULL);//----------------時間計測開始
  
  for(int i=0; i<N; i++){
    X = Get_Rand();
    Y = Get_Rand();
    SUM += Monte_Carlo(X, Y);
  }

  SUM = (SUM/N)*4.0L;
  
  gettimeofday(&t, NULL);//--------------------時間計測終了
  startTime = s.tv_sec + (double)(s.tv_usec * 1e-6);
  endTime = t.tv_sec + (double)(t.tv_usec * 1e-6);
  
  //printf("%f ms\t PI = %.10Lf\n",(endTime - startTime) * 1000, SUM);
  printf("%d %f %.10Lf\n",N/1000000, (endTime - startTime) * 1000, SUM);
  return 0;
}
Beispiel #2
0
void *Thread_Func(void *RET){
  void *p = malloc(sizeof(int));
  ret_p Ret = (ret_p)RET;

  int Number = Ret->max;
  int N = Ret->N;
  int *x;
  x = malloc(sizeof(int));
  pthread_mutex_lock(&mutex); //mutexをロック
  if(struct_pop(Ret, x) == -1)
    printf("値がスタックされていません\n");
  pthread_mutex_unlock(&mutex); //mutexをアンロック
  
  for(int i=0; i<N/Number; i++){
   double X = Get_Rand();
   double Y = Get_Rand();
   *(int *)p += Monte_Carlo(X, Y);
  }
  //printf("Thread%2d : thread_ID = %u SUM = %d\n",*x,(unsigned int)pthread_self(), *(int *)p);
  pthread_exit(p);
}
Beispiel #3
0
char deploy_the_Queen()
{
	
	int pos_x,pos_y,_x,_y,x,y,Queen_Counter_Confirm=0,Bspace=0;
	char AllowDeploy1 = 'F',AllowDeploy2 = 'F',Space = 'F';
	for(y=0;y<N;y++)
	{
		for(x=0;x<N;x++)
		{
			if(C_board[y][x] == 'Q')
			{
				Queen_Counter_Confirm++;
				
			}
			
		}
	}
	if(Queen_Counter_Confirm != QCounter)
	{
		printf("\nQCounter Error\nQueens %i QCounter %i",Queen_Counter_Confirm,QCounter);
	}
	if(QCounter < N)
	{
		for(y=0;y<N;y++)
		{
			for(x=0;x<N;x++)
			{
				if(C_board[y][x] == '_')
				{
					Space = 'T';
					break;
				}
			}
			if(Space == 'T')
			{
				break;
			}
			
		}
		if(Space == 'T')
		{
			do
			{
				pos_x = Get_Rand((N-1),(N-N));
				pos_y = Get_Rand((N-1),(N-N));
				
			
				for(y=0;y<(QCounter+1);y++)
				{
					if(QueenHistory[y][0] != -1 )
					{
						if(QueenHistory[y][1] == pos_y && QueenHistory[y][2] == pos_x)
						{
							AllowDeploy1 = 'F';
							printf("\nDont Allow\n");
							for(_y=0;_y<N;_y++)
							{
								for(_x=0;_x<N;_x++)
								{
									if(C_board[_y][_x]=='_')
									{
										Bspace++;
									}
								}
							}
							if(Bspace<3)
							{
								printf("\nNo other space on the board\nQueen Removal Function initiated\n\n");
								RemoveQueen();
								
							}
							
							break;
						}
						else
						{
							continue;
						}
						
					}
				}
				if(C_board[pos_y][pos_x] == '_')
				{
					AllowDeploy2 = 'T';
				}
				else
				{
					AllowDeploy2 = 'F';
				}
			}while(AllowDeploy2 != 'T' && AllowDeploy1 != 'T');
		
			printf("\n\nx = %i  y = %i\n\n",pos_x,pos_y);
			C_board[pos_y][pos_x] = 'Q';
			Queens_LOC[QCounter][0] = QCounter;
			Queens_LOC[QCounter][1] = pos_y;
			Queens_LOC[QCounter][2] = pos_x;
			QueenHistory[QHCounter][0] = QHCounter;
			QueenHistory[QHCounter][1] = pos_y;
			QueenHistory[QHCounter][2] = pos_x;
			QCounter++;
			QHCounter++;
		
			Queens_Attack_range(pos_y,pos_x);
			print_Board();
			printf("\nQueen Added\n");
			printQueenHistory();
			printf("\nQueen Counter = %i\n",QCounter);
			system("pause");
		}
		else
		{
			if(Remove_Queen == 0 && QCounter > 0)
			{
				RemoveQueen();
				Remove_Queen++;
			}
			else
			{
				if(QCounter > 0)
				{
					for(x=0;x<(Remove_Queen);x++)
					{
						RemoveQueen();
						if(Remove_Queen < 8)
						{
							Remove_Queen++;
						}
						else
						{
							Remove_Queen = 0;
						}
					}
				}
			}
			
		}
	}
	else
	{
		system("cls");
		printf("\n\n\n\t\tProblem Solved\n\n");
		print_Board();
		system("pause");
		exit(-1);
		
		
	}


}