Esempio n. 1
0
void test_barrier(size_t num_workers)
{
  barrier my_barrier(num_workers);

  std::vector<std::thread> threads;

  for(int i = 0; i < num_workers; i++)
  {
    threads.emplace_back([&my_barrier] {
      for(int i = 0; i < 1000; i++)
      {
        my_barrier.enter();
        my_barrier.enter();
      }
     } );
  }

  for(int i = 0; i < num_workers; i++)
  {
    if(threads[i].joinable())
    {
      threads[i].join();
    }
  }
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
	int argc;
	char* argv;
	
	int num_th, th_id;
	
	char* relative_path_to_output_file;
	
	double start, time;
	relative_path_to_output_file = argv[1];
	
	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &th_id);
	MPI_Comm_size(MPI_COMM_WORLD, &num_th);

	if (th_id == 0)
		start = MPI_Wtime();

	my_barrier();	

	if (th_id == 0)
	{
		time = MPI_Wtime() - start;
		write_to_file(relative_path_to_output_file, time);
	}
	MPI_Finalize();
	return 0;
}
int main(int argc, char *argv[]) {

    double t1;
    double t2;
    double t3;
    FILE *fptr;

    char outFile[BUFFER];

    strcpy(outFile, argv[1]);

    /* Initialize MPI stuff */
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &th_id);
    MPI_Comm_size(MPI_COMM_WORLD, &num_th);

    t1 = MPI_Wtime();
    my_barrier();
    t2 = MPI_Wtime();

    if (th_id == MASTER) {
        fptr = openFile(outFile);
        t3 = (t2 - t1) * MILLISECONDS;
        fprintf(fptr, "%.3f\n", t3);
        printf("%.3f\n", t3);
        fclose(fptr);
    }
    // end all nodes
    MPI_Finalize();
    return 0;
 }
int main(int argc, char *argv[])
{	

		int world_size;
		int world_rank;

		char processor_name[MPI_MAX_PROCESSOR_NAME];
		int name_len;

		// **********  INITIALIZING + PROCESS INFO RETRIEVE ***********
		// Initialize the MPI environment
		MPI_Init(&argc, &argv);

		// Get the number of processes
		MPI_Comm_size(MPI_COMM_WORLD, &world_size);

		// Get the rank of the processor
		MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

		// Get the name of the processor
		MPI_Get_processor_name(processor_name, &name_len);


		printf("[%s]: Process #%d STARTS.\n", getTimeString(), world_rank);
		// Each process will carry out some calculation or operations, which takes different times.
		if (world_rank % 2 == 1){ 
				sleep(4);
		} else {
				sleep(1);
		}
		
		printf("[%s]: Process #%d is ENTERING barrier.\n", getTimeString(), world_rank);
		// Call the barrier function here
		if (determineBarrierType(argc, argv) <= 0){
				my_barrier(MPI_COMM_WORLD);
		}else {
				MPI_Barrier(MPI_COMM_WORLD);
		}
		// print the message after the barrier, by each process.
		printf("[%s]: Process #%d: PASSED barrier.\n", getTimeString(), world_rank);

		// Finalize the MPI environment
		MPI_Finalize();
		return 0;
}