Ejemplo n.º 1
0
int main(int argc, char** argv)
{
  MPI_Init(NULL, NULL); /* initialize the MPI universe */
  MPI_Comm_size(MPI_COMM_WORLD, &world_size); /* get number of processors */
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* get my id */
  MPI_Get_processor_name(processor_name, &name_len); /* get my name */

  // initialize with a random seed base on the process id
  srand((int)getpid());

  // determine if I am the root node (boss)
  if (my_rank == 0) {
    doBoss();
  } else {
    doWorker();
  }

  // call the cleanup function
  MPI_Finalize();

  return 0;
}
Ejemplo n.º 2
0
/**MAIN**/
int main(int argc,char** argv){

	int rank,size;

	int matrSize = SIZE;
	int initStyle = INIT_STYLE_RANDOM;

	MPI_Init(&argc,&argv);
	
	MPI_Comm_rank(MPI_COMM_WORLD,&rank);
	MPI_Comm_size(MPI_COMM_WORLD,&size);

	if(argc == 2){
		matrSize = atoi(argv[1]);
	}else if(argc == 3){
		matrSize = atoi(argv[1]);
		initStyle = atoi(argv[2]);
		if(initStyle == 0){
			initStyle = INIT_STYLE_SIMPLE;
		}else{
			initStyle = INIT_STYLE_RANDOM;
		}
	}

	printf("%d matrsize: %d\n",rank,matrSize);

	if(rank == 0){
		//boss node;
		doBoss(size,matrSize,initStyle);
	}else{
		//worker node;
		doWorker(rank,size,matrSize);
	}


	MPI_Finalize();
	return 0;
}
Ejemplo n.º 3
0
Archivo: test.c Proyecto: luoken/cs370
int main(int argc, char** argv)
{
  // MPI_Status status;
  // Initialize the MPI environment
  MPI_Init(NULL, NULL);

  // Get the number of processes
  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Get_processor_name(processor_name, &name_len);

  int proceed_flag = 0;
  int n = 0;
  int z = 0;
  int seed = 0;

  if (my_rank == 0) {
    proceed_flag = getArguments(argc, argv, &n, &z, &seed);
  }

  // broadcast instruction
  MPI_Bcast(&proceed_flag, 1, MPI_INT, 0, MPI_COMM_WORLD);

  if (proceed_flag == TRUE) {
    if (my_rank == 0) {
      doManager(n, z, seed);
    } else {
      doWorker();
    }
  }

  printf("[%s.%d] program completed\n", processor_name, my_rank);

  // Finalize the MPI environment.
  MPI_Finalize();

  return 0;
}