예제 #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;
}
예제 #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;
}