コード例 #1
0
int main(int argc, char *argv[]) { 

  double start1,start2,end1,end2;
  int r;

  init1(); 

  start1 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    runloop(1);
  } 

  end1  = omp_get_wtime();  

  valid1(); 

  printf("Total time for %d reps of loop 1 = %f\n",reps, (float)(end1-start1)); 


  init2(); 

  start2 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    runloop(2);
  } 

  end2  = omp_get_wtime(); 

  valid2(); 

  printf("Total time for %d reps of loop 2 = %f\n",reps, (float)(end2-start2)); 

} 
コード例 #2
0
ファイル: guided_64.c プロジェクト: josh-gree/omp_final
int main(int argc, char *argv[]) { 

  double start1,start2,end1,end2;
  int r;

  init1(); 

  start1 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    loop1();
  } 

  end1  = omp_get_wtime();  


  double out1 = valid1();
  printf("%f,", (float)(end1-start1)); 


  init2(); 

  start2 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    loop2();
  } 

  end2  = omp_get_wtime(); 


  double out2 = valid2();
  printf("%f,guided,64,%.10f,%.10f\n", (float)(end2-start2), out1, out2); 

} 
コード例 #3
0
int win(int a[]){
	int b[11];
	int i=0 ;
	int ret= 0;
	set(b);

	for(i=0 ; i< 11 ; i++){
		if ( valid1(i,a) ){
			copy(b,a);
			put1(i,b);
			ret|= !win(b);
		}
		if ( valid2(i,a) ){
			copy(b,a);
			put2(i,b);
			ret|= !win(b);
		}
		if ( valid3(i,a) ){
			copy(b,a);
			put3(i,b);
			ret|= !win(b);
		}
	}
	return ret;
}
コード例 #4
0
int main(int argc, char *argv[]) { 

	loop_time = malloc(omp_get_max_threads()*sizeof(int));
	waiting_time = malloc(omp_get_max_threads()*sizeof(int));
	int i;
	for(i=0; i<omp_get_max_threads(); i++)
	{
		loop_time[i] = 0;
		waiting_time[i] = 0;
	}
  double start1,start2,end1,end2;
  int r;

  init1(); 

  start1 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    runloop(1);
  } 

  end1  = omp_get_wtime();  

  valid1(); 

  printf("Total time for %d reps of loop 1 = %f\n",reps, (float)(end1-start1)); 
	printf("#thread\ttime thread spent working\n");
	for(i=0;i<omp_get_max_threads(); i++)
	{
		printf("\t%d\t%d\t%d\n", i, loop_time[i], waiting_time[i]);
		loop_time[i] = 0;
		waiting_time[i] = 0;
	}

  init2(); 

  start2 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    runloop(2);
  } 

  end2  = omp_get_wtime(); 

  valid2(); 

  printf("Total time for %d reps of loop 2 = %f\n",reps, (float)(end2-start2)); 

	printf("#thread\ttime thread spent working\n");
	for(i=0;i<omp_get_max_threads(); i++)
	{
		printf("\t%d\t%d\t%d\n", i, loop_time[i], waiting_time[i]);
	}
} 
コード例 #5
0
int main(int argc, char *argv[]) { 

  double start1,start2,end1,end2;
  int r;
  int i;
  
  /* Init locks */
  for(i=0;i<MAX_PROCS;i++) omp_init_lock(&(remaining_iters_lock[i]));

  init1(); 

  start1 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    runloop(1);
  } 

  end1  = omp_get_wtime();  

  valid1(); 

  printf("Total time for %d reps of loop 1 = %f\n",reps, (float)(end1-start1)); 


  init2(); 

  start2 = omp_get_wtime(); 

  for (r=0; r<reps; r++){ 
    runloop(2);
  } 

  end2  = omp_get_wtime(); 

  valid2(); 

  printf("Total time for %d reps of loop 2 = %f\n",reps, (float)(end2-start2)); 

  for(i=0;i<MAX_PROCS;i++) omp_destroy_lock(&(remaining_iters_lock[i]));

} 
コード例 #6
0
ファイル: felix.c プロジェクト: PersistingVoices/HPC-C
int main(int argc, char *argv[]) {
    FILE *pFile;

    double start1,start2,end1,end2,time1,time2;
    int r;

    init1();

    start1 = omp_get_wtime();

    for (r=0; r<reps; r++){
        loop1();
    }

    end1  = omp_get_wtime();

    valid1();
    time1 = (float)(end1-start1);
    printf("Total time for %d reps of loop 1 = %f\n",reps, time1);

    pFile = fopen ("myfile.txt" , "w");
    if (pFile == NULL) perror ("Error opening file");

    init2();

    start2 = omp_get_wtime();

    for (r=0; r<reps; r++){
        loop2();
    }

    end2  = omp_get_wtime();

    valid2();

    time2 = (float)(end2-start2);
    printf("Total time for %d reps of loop 2 = %f\n",reps, time2);
    printf("This file is functional\n");
    fprintf(pFile,"%lf\t%lf\n",time1, time2);
    fclose(pFile);
}
コード例 #7
0
ファイル: main.cpp プロジェクト: Tpimp/EZMemoryInit
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    qmlRegisterType<MemoryInitFile>("MemoryInitialization",1,0,"MemoryInitFile");
    qmlRegisterType<MemoryChunk>("MemoryInitialization", 1, 0, "MemoryChunk");
    qmlRegisterType<ChunkData>("MemoryInitialization", 1, 0, "ChunkData");
    QQmlApplicationEngine engine;

    MemoryInitFile  active_file(&app);
    QRegExp   regexp("[0-9abcdef]*");
    QRegExp   regexp2("[0-9]*");
    AddressValidator valid(&active_file,&app);
    ValueValidator   valid2(&active_file, &app);
    valid.setRegExpression(regexp);
    valid2.setRegExpression(regexp2);
    engine.rootContext()->setContextProperty("MemoryFileEngine",&active_file);
    engine.rootContext()->setContextProperty("AddressValidator",&valid);
    engine.rootContext()->setContextProperty("ValueValidator",&valid2);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
コード例 #8
0
 int splitArray(vector<int>& arr, int m) {
     int maxi = 0;
     int n = (int)arr.size();
     vector<long long> sums(n + 1, 0LL);
     
     for(int i = 0; i < n; i++) {
         maxi = max(maxi, arr[i]);
         sums[i + 1] = sums[i] + arr[i];
     }
     
     if(m == 1) return (int)sums[n];
     if(m == arr.size()) return maxi;
     
     long long left = maxi, right = sums[n];
     while(left <= right) {
         long long mid = left + (right - left) / 2LL;
         if(valid2(mid, sums, m)) {
             right = mid - 1;
         } else {
             left = mid + 1;
         }
     }
     return (int)left;
 }
コード例 #9
0
ファイル: jade.c プロジェクト: mariaaprilrose/CS180MP1
int main(){
	int i, j;  //for loops
	int choice; //option
	int height; //height of tree
	int size; //size of array
	int done = 0; //if user's done using the program, initialized as false
	int validation;

	output = fopen("2014.out","w"); //open output file

	while(done != 1){
		choice = printChoice();
		if(choice == 1){
			char data[MAX_SIZE];
			char tag[MAX_SIZE];

			//GET DATA
			printf("DATA: ");
			scanf("%[^\n]",data);
			getchar();

			//PRINT DATA ARRAY
			fprintf(output,"DATA: " );
			for(i=0;i<strlen(data);i++){
				fprintf(output,"%c", data[i]);
			}
			fprintf(output,"\n" );

			//GET TAGS
			printf("TAG: ");
			scanf("%[^\n]",tag);
			getchar();

			//PRINT TAG ARRAY
			fprintf(output,"TAG: " );
			for(i=0;i<strlen(tag);i++){
				fprintf(output,"%c", tag[i]);
			}
			fprintf(output,"\n" );

			if (strlen(data) != strlen(tag)){ //not equal input
				fprintf(output,"Input is invalid.\n\n");
			}

			else{
				getInput(data);
				getInput(tag);

				size = strlen(data);

				if(size==1 && tag[0] == '0'){ //tree with only one node
					fprintf(output,"Postorder: %c\n",data[0]);
					fprintf(output,"Levelorder: %c\n",data[0]);
					fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
					fprintf(output,"      %c\n\n",data[0]);
				}

				else if(size==1 && tag[0] == '1'){ //one node with children is invalid
					fprintf(output,"Input is invalid.\n\n");
				}

				else{
					if(tag[0] == '0'){
						fprintf(output,"Input is invalid.\n\n");
					}

					else{
						validation = valid1(tag,size);
						if(validation == -1){
							Node *root = Tree(data,tag,size);
							fprintf(output,"Postorder: ");
							height = printPost(root,output,0);
							fprintf(output,"\nLevel Order: ");
							for(i=0;i<height;i++){
									printLevel(root, i, output);
							}
							fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
							printTable(root,output);
							fprintf(output,"\n\n");
						}
						else{
							fprintf(output,"Input is invalid.\n\n");
						}
					}
				}
			}
		}

		else if(choice == 2){
			char filename[MAX_SIZE];
			char data_array[MAX_SIZE];
			char tag_array[MAX_SIZE];
			char data = ' ';
			int index = 0;

			printf("Filename: ");
			scanf("%s",filename);

			input = fopen(filename,"r");

			while(!feof(input)){
				index = 0;
				while(index < MAX_SIZE){
					data_array[index] = ' ';
					tag_array[index] = -1;
					index++;
				}
				index = 0;
				while(data!=':' && !feof(input)){
					data = fgetc(input);
				}
				fgetc(input);
				while(data!='\n' && !feof(input)){
					data = fgetc(input);
					if(data!=' '){
						data_array[index] = data;
						index++;
					}
				}
				int index = 0;
				while(data!=':' && !feof(input)){
					data = fgetc(input);
				}
				fgetc(input);
				data = fgetc(input);
				while(data!='\n' && !feof(input)){
					if(data!=' '){
						tag_array[index] = atoi(&data);
						index++;
					}
					data = fgetc(input);
				}

				fprintf(output,"DATA: " );
				int i;
				for(i=0;i<index;i++){
					if(i==index-1){
						fprintf(output,"%c", data_array[i]);
					}
					else{
					fprintf(output,"%c", data_array[i]);
					}
				}
				fprintf(output,"\n"); 

				fprintf(output,"TAG: " );
				for(i=0;i<index;i++){
					fprintf(output,"%d", tag_array[i]);
				}
				fprintf(output,"\n");

				int size = strlen(data_array);

				if(index==1 && tag_array[0] == 0){
					fprintf(output,"Postorder: %c\n",data_array[0]);
					fprintf(output,"Levelorder: %c\n",data_array[0]);
					fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
					fprintf(output,"      %c\n\n",data_array[0]);
				}
				else if(index==1 && tag_array[0] != 1){
					fprintf(output,"Input is invalid.\n\n");
				}
				else{
					//print(tag_array,size1);
					if(tag_array[0] == 0){
						fprintf(output,"Input is invalid.\n\n");
					}
					else{
						int validation = valid2(tag_array,index);
						if(validation == -1){
							Node *head_node = Tree2(data_array,tag_array,index);
							fprintf(output,"Postorder: ");
							height = printPost(head_node, output,0);
							fprintf(output,"\nLevelorder: ");
							int i = 0;
							for(i=0;i<height;i++){
								printLevel(head_node, i, output);
							}
							fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
							printTable(head_node,output);
							fprintf(output,"\n\n");
							}
						else{
							fprintf(output,"Input is invalid.\n\n");
						}
					}
				}
			}
			fclose(input);
		}

		else if(choice==3){
			printf("Exits.\n");
			done = 1;
		}

		else{
			printf("Wrong input.\n");
		}
	}
	fclose(output);
}
コード例 #10
0
ファイル: 24-game.c プロジェクト: pocketzeroes/proekt
bool valid3(double a, double b, double c){
    if (valid2(a+b, c) || valid2(a-b, c) || valid2(a*b, c) || b&&valid2(a/b, c)) return true;
    if (valid2(a, b+c) || valid2(a, b-c) || valid2(a, b*c) || c&&valid2(a, b/c)) return true;
    return false;
}
コード例 #11
0
ファイル: GUIDED64.c プロジェクト: PersistingVoices/HPC-C
int main(int argc, char *argv[]) { 
	FILE *pFile2,*pFile1;
	FILE *pipe_gp1;

	double start1,start2,end1,end2,time1,time2;
	int r,i=0,rand(void);

	pFile1 = fopen ("Data/GUIDED-n-file1.dat" , "w");
	pFile2 = fopen ("Data/GUIDED-n-file2.dat" , "w");

	if (pFile1 == NULL || pFile2 ==NULL) perror ("Error opening file");

	for(i=0;i<100;i++)
	{
		init1(); 
		start1 = omp_get_wtime(); 
		for (r=0; r<reps; r++){ 
			loop1();
		} 
		end1  = omp_get_wtime();  

		valid1(); 
		time1 = (float)(end1-start1);
		//printf("Total time for %d reps of loop 1 = %f\n",reps, time1); 


		init2(); 
		start2 = omp_get_wtime(); 
		for (r=0; r<reps; r++){ 
			loop2();
		} 
		end2  = omp_get_wtime(); 

		valid2(); 
		time2 =  (float)(end2-start2);
		// printf("Total time for %d reps of loop 2 = %f\n",reps, time2);
		// printf("This file is functional\n");

		// Write everything in the file, before plotting. 
		fprintf(pFile1,"%lf\t%d\t%lf\n",(i+1)*time1,i+1,time1);
		fprintf(pFile2,"%lf\t%d\t%lf\n",(i+1)*time2,i+1,time2); 
	}
	printf("\n\t\t\tWritten to 'GUIDED-n-file1.dat & GUIDED-n-file2.dat'\n\n"); 
	fclose(pFile1);
	fclose(pFile2);

	// Gnu-plot script
	pipe_gp1 = popen("gnuplot","w");
	fputs("set terminal wxt 0\n ", pipe_gp1);
	fputs("unset key\n ", pipe_gp1);
	fputs("set hidden3d\n ", pipe_gp1);
	fputs("set dgrid3d 50,50\n ", pipe_gp1);
	fputs("set title '3DPlot1'\n ", pipe_gp1);
	fputs("set xlabel'Random Axis Arrangement (for 3-d plot)'\n ", pipe_gp1);
	fputs("set ylabel 'Iteration Number'\n ", pipe_gp1);
	fputs("set zlabel 'Time taken for 100 iterations'\n ", pipe_gp1);
	fputs("splot 'Data/GUIDED-n-file1.dat' u 1:2:3 w lines \n ", pipe_gp1);
	fputs("set terminal png  size 1200,800\n ", pipe_gp1); 
	fputs("set output 'Plots/GUIDED-n-3dplot1.png'\n ", pipe_gp1);
	fputs("replot\n ", pipe_gp1);


	fputs("reset\n ", pipe_gp1);

	fputs("set terminal wxt 0\n ", pipe_gp1);
	fputs("unset key\n ", pipe_gp1);
	fputs("set title '2DPlot1'\n ", pipe_gp1);
	fputs("set xlabel 'Iteration Number'\n ", pipe_gp1);
	fputs("set ylabel 'Time taken for 100 iterations'\n ", pipe_gp1);
	fputs("plot 'Data/GUIDED-n-file1.dat' u 2:3 w lines \n ", pipe_gp1);
	fputs("set terminal png  size 1200,800\n ", pipe_gp1); 
	fputs("set output 'Plots/GUIDED-n-2dplot1.png'\n ", pipe_gp1);
	fputs("replot\n ", pipe_gp1);

	fputs("reset\n ", pipe_gp1);

	fputs("set terminal wxt 0\n ", pipe_gp1);
	fputs("unset key\n ", pipe_gp1);
	fputs("set hidden3d\n ", pipe_gp1);
	fputs("set dgrid3d 50,50\n ", pipe_gp1);
	fputs("set title 'Plot2'\n ", pipe_gp1);
	fputs("set xlabel'Random Axis Arrangement (for 3-d plot)'\n ", pipe_gp1);
	fputs("set ylabel 'Iteration Number'\n ", pipe_gp1);
	fputs("set zlabel 'Time taken for 100 iterations'\n ", pipe_gp1);
	fputs("splot 'Data/GUIDED-n-file2.dat' u 1:2:3 w lines \n ", pipe_gp1);
	fputs("set terminal png  size 1200,800\n ", pipe_gp1); 
	fputs("set output 'Plots/GUIDED-n-3dplot2.png'\n ", pipe_gp1);
	fputs("replot\n ", pipe_gp1);

	fputs("reset\n ", pipe_gp1);

	fputs("set terminal wxt 0\n ", pipe_gp1);
	fputs("unset key\n ", pipe_gp1);
	fputs("set title '2DPlot1'\n ", pipe_gp1);
	fputs("set xlabel 'Iteration Number'\n ", pipe_gp1);
	fputs("set ylabel 'Time taken for 100 iterations'\n ", pipe_gp1);
	fputs("plot 'Data/GUIDED-n-file2.dat' u 2:3 w lines \n ", pipe_gp1);
	fputs("set terminal png  size 1200,800\n ", pipe_gp1); 
	fputs("set output 'Plots/GUIDED-n-2dplot2.png'\n ", pipe_gp1);
	fputs("replot\n ", pipe_gp1);

	pclose(pipe_gp1);

	printf("\n\t\t\tPlots at 'GUIDED-n-plot1.png & GUIDED-n-plot2.png' for loop1 & loop2  (100I)\n\n"); 
}