Exemplo n.º 1
0
int main(void) {
	double** matrix; //указатель на массив массивов
	int n, m, t; // размерность и количество потоков
	double timeStart, timeEnd; // переменные измерения времени

	MatrixInicialization(matrix, n, m, t); // Выделение памяти под матрицу и инициализация переменных

	RandDataIni(matrix, n, m, t); // Заполнение матрицы случайными числами

	/*printf("\nNot sorted matrix: \n");
	Out(matrix, n, m);*/

	timeStart = omp_get_wtime(); // Начало отсчёта	
	MatrixOddEvenSort(matrix, n, m, t); // Сортировка
	timeEnd = omp_get_wtime(); // Конец отсчёта

	/*printf("Sorted matrix: \n");
	Out(matrix, n, m);*/

	printf("Runtime: %f\n", timeEnd - timeStart);
	printf("\n");

	Termination(matrix, n); // Освобождение памяти

	return 0;
}
Exemplo n.º 2
0
void
main (INT argc,       /* Number of command line arguments */
      char *argv[],   /* Array of command line arguments */
      char *envp[])   /* Array of environment pointers */
{
   WN          *pu;
   INT32        inp_file_count;
   PU_Info     *pu_tree, *current_pu;

   /* Here are things that every process driver should do as soon as
    * possible upon start-up.
    */
   MEM_Initialize ();
   Init_Error_Handler (10);
   Set_Error_Line (ERROR_LINE_UNKNOWN);
   Set_Error_Phase ("IR Walker");
   Set_Error_File (NULL);

   Init_Operator_To_Opcode_Table ();
    
   /* Process the input file */
   inp_file_count = Get_Irb_File_Name (argc, argv);
   if (inp_file_count == 0)
   {
      Usage ();
      fprintf (stderr, "ERROR: missing input file on command line\n");
   }
   else if (inp_file_count > 1)
   {
      Usage ();
      fprintf (stderr, "ERROR: too many input files on command line\n");
   }
   else if (stat (Irb_File_Name, &statbuf) != 0)
   {
      fprintf (stderr, "ERROR: input file (%s) does not exist\n",
	       Irb_File_Name);
   }
   else
   {

#ifdef WRITE_IRB
      /* Setup output file */
      if (!oflag)
	(void) strcpy (filename_out, filename_in);
      (void) sprintf (temp_filename, "%s$%d", filename_out, (INT32) getpid ());
      (void) remove (temp_filename);
#endif

      /* User defined initialization code */
      Initialization ();

      /* Get the global symbol table, the string table, the constant table,
       * and the initialization table.
       */
      (void) Open_Input_Info (Irb_File_Name);
      pu_tree = Read_Global_Info (NULL);

#ifdef WRITE_IRB
      (void) Open_Output_Info (temp_filename);
#endif

      /* Process global symbol table. */
      process_stab (Global_Symtab);

      /* Loop thru all the PUs */
      process_pu (pu_tree);

      /* User defined termination code */
      Termination ();

#ifdef WRITE_IRB
      /* Finish up output file */
      Write_Global_Info (pu_tree);
      Close_Output_Info ();
      (void) remove (filename_out);
      (void) rename (temp_filename, filename_out);
#endif

   }
   
   exit (0);
} /* main */
int main()
{
	int icount = 0;  //指示
	int gencount = 0;
	int tim;   //指示TIME
	int res = 0;  //指示RESPONSE
	
	FILE *fp;
	fp = fopen("TimeSequence.txt","r+t");
	while(res < RESPONSE)
	{
		for(gencount = 0; gencount < GENENUM; gencount++)
		{
			for (tim = 0; tim < TIME; tim++)
		    {
				fscanf(fp, "%lf", &data[res][gencount][tim]);
		    }
		}
		res = res + 1;
	}
	fclose(fp);

	int flag = 0;
	srand((unsigned)time(NULL));  

	grpGA grp;
	pgrpGA pgrp = &grp;
	grp.generationCount = 0;
	grp.generationMax = 5000;  //遗传算法迭代次数
	grp.probCross = 0.9;     
	grp.probMutat = 0.1;    
	grp.size = SIZEGROUP;  //种群大小

	genGA ind[SIZEGROUP];
	pgenGA pind[SIZEGROUP];

	for(icount = 0; icount < SIZEGROUP; icount++)
	{
		pind[icount] = &ind[icount];
	}
	
	int u = 0;
	for(u = 0; u < GENENUM; u++)
	{
		printf("%d node learn\n", u);
		FILE *fp1;
		fp1 = fopen("Individuals.txt","r+t");
		icount = 0;
		while(icount < SIZEGROUP)
		{
			for (gencount = 0; gencount < GENENUM; gencount++)
			{
				fscanf(fp1, "%d", &populationMirror[icount][gencount]);
			}
			icount = icount + 1;
		}
		fclose(fp1);

		genExpect = 0;
		for(res = 0; res < RESPONSE; res++)
		{
			for(gencount = 0; gencount < GENENUM; gencount++)
			{
				genWigh[res][gencount] = 0;
			}
		}

		for(gencount = 0; gencount < GENENUM; gencount++)
		{
			genTest[gencount] = 0;
			genWighMean[gencount] = 0;
			elite[gencount] = 0;
			eliteWeight[gencount] = 0;
		}
	    
		eliteFitness = 0;

		do
		{
			Initial(pind);

			ErrorCmp(pind, data, populationMirror, genTest, genWigh, genWighMean, genExpect, &u);
			Fitness(pind);
			Optimal(pind, elite, &eliteFitness, populationMirror, genWighMean, eliteWeight);
			
			flag = Termination(pgrp);
			if(flag)
			{
				break;
			}

			BinaryTourment(pind, pgrp, populationMirror);
			Crossover(pind, pgrp, populationMirror);  
			Mutation(pind, pgrp, populationMirror); 
		
		}while(1);

		ResultOutput(pind, elite, pgrp, eliteWeight);
	}
	
	return 0;
}