示例#1
0
int main(int argc, char **argv) {
  /* Timing variables */
  struct timeval etstart, etstop;  /* Elapsed times using gettimeofday() */
  struct timezone tzdummy;
  clock_t etstart2, etstop2;  /* Elapsed times using times() */
  unsigned long long usecstart, usecstop;
  struct tms cputstart, cputstop;  /* CPU times for my processes */

  /* Process program parameters */
  parameters(argc, argv);

  /* Initialize A and B */
  initialize_inputs();

  /* Print input matrices */
  print_inputs();

  /* Start Clock */
  printf("\nStarting clock.\n");
  gettimeofday(&etstart, &tzdummy);
  etstart2 = times(&cputstart);

  /* Gaussian Elimination */
  gauss();

  /* Stop Clock */
  gettimeofday(&etstop, &tzdummy);
  etstop2 = times(&cputstop);
  printf("Stopped clock.\n");
  usecstart = (unsigned long long)etstart.tv_sec * 1000000 + etstart.tv_usec;
  usecstop = (unsigned long long)etstop.tv_sec * 1000000 + etstop.tv_usec;

  /* Display output */
  print_X();

  /* Display timing results */
  printf("\nElapsed time = %g ms.\n",
         (float)(usecstop - usecstart)/(float)1000);

  printf("(CPU times are accurate to the nearest %g ms)\n",
         1.0/(float)CLOCKS_PER_SEC * 1000.0);
  printf("My total CPU time for parent = %g ms.\n",
         (float)( (cputstop.tms_utime + cputstop.tms_stime) -
         (cputstart.tms_utime + cputstart.tms_stime) ) /
         (float)CLOCKS_PER_SEC * 1000);
  printf("My system CPU time for parent = %g ms.\n",
         (float)(cputstop.tms_stime - cputstart.tms_stime) /
         (float)CLOCKS_PER_SEC * 1000);
  printf("My total CPU time for child processes = %g ms.\n",
         (float)( (cputstop.tms_cutime + cputstop.tms_cstime) -
         (cputstart.tms_cutime + cputstart.tms_cstime) ) /
         (float)CLOCKS_PER_SEC * 1000);
      /* Contrary to the man pages, this appears not to include the parent */
  printf("--------------------------------------------\n");

  exit(0);
}
示例#2
0
int main(int argc, char **argv) {

  parameters(argc, argv);
  initialize_inputs();
  print_inputs();

  gauss();

  print_X();
  
  exit(0);
}
示例#3
0
int main(int argc, char **argv) {
  
  /* Timing variables */
  double start_t;
  double end_t;
  
  /* MPI Variables */
  int my_rank;
  int p;
  int dest = 0;
  
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &p);
  
  if(my_rank == 0) {
	parameters(argc, argv);
  }
  MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD);
  
  if(my_rank == 0) {
	float A[N*N], B[N], X[N];
	/* Initialize A and B */
	initialize_inputs(A, B, X);

	/* Print input matrices */
	print_inputs(A, B);

	/* Start Clock */
	printf("\nStarting clock.\n");
	start_t = MPI_Wtime();
	
    gauss(A, B, X, my_rank, p);
	
	/* Stop Clock */
	end_t = MPI_Wtime();
	printf("Stopped clock.\n");
  
	/* Display output */
	print_X(X);

	/* Display timing results */
	printf("\nElapsed time = %g s\n", end_t - start_t);
	printf("--------------------------------------------\n");
  } else {
	workerGauss(my_rank, p);
  }
  
  MPI_Finalize();
}
示例#4
0
int main(int argc, char **argv) {

    /* Prototype functions*/
    void gauss();

    MPI_Init(&argc, &argv);

    /* Get my process rank */
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    /* Find out how many processes are being used */
    MPI_Comm_size(MPI_COMM_WORLD, &p);

    printf("\nProcess number %d of %d says hi\n",
            my_rank+1, p);

    /* Every process reads the parameters to prepare dimension */
    parameters(argc, argv);

    /* Every process must allocate memory for the arrays */
    allocate_memory();

    if ( my_rank == SOURCE ) {
        /* Initialize A and B */
        initialize_inputs();

        /* Print input matrices */
        print_inputs();
    }

    /*printf("\nProcess number %d of %d says hi\n",
            my_rank+1, p);*/

    gauss();

    if ( my_rank == SOURCE ) {

        /* Print input matrices */
        print_A();
        print_B();
        print_X();
    }

    /* The barrier prevents any process to reach the finalize before the others have finished their communications */
    MPI_Barrier(MPI_COMM_WORLD);

    /* Free memory used for the arrays that we allocated previously */
    free_memory();

    MPI_Finalize();
}
示例#5
0
int main(int argc, char **argv) {
  /* Timing variables */
  struct timeval etstart, etstop;  /* Elapsed times using gettimeofday() */
  struct timezone tzdummy;
  clock_t etstart2, etstop2;  /* Elapsed times using times() */
  unsigned long long usecstart, usecstop;
  struct tms cputstart, cputstop;  /* CPU times for my processes */

  ID = argv[argc-1];
  argc--;

  /* Process program parameters */
  parameters(argc, argv);

  /* Initialize A and B */
  initialize_inputs();

  /* Print input matrices */
  print_inputs();

  /* Start Clock */
  printf("\nStarting clock.\n");
  gettimeofday(&etstart, &tzdummy);
  etstart2 = times(&cputstart);

  /* Gaussian Elimination */
  gauss();

  /* Stop Clock */
  gettimeofday(&etstop, &tzdummy);
  etstop2 = times(&cputstop);
  printf("Stopped clock.\n");
  usecstart = (unsigned long long)etstart.tv_sec * 1000000 + etstart.tv_usec;
  usecstop = (unsigned long long)etstop.tv_sec * 1000000 + etstop.tv_usec;

  /* Display output */
  print_X();

  /* Display timing results */
  printf("\nElapsed time = %g ms.\n",
	 (float)(usecstop - usecstart)/(float)1000);


}
示例#6
0
int main(int argc, char **argv) {
    ID = argv[argc-1];
    argc--;
    
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &myid);
    MPI_Comm_size(MPI_COMM_WORLD, &procs);
    printf("\nProcess number %d", myid);
    /* Process program parameters */
    parameters(argc, argv);
    
    //alocate memory
    A = (float*)malloc(N*N*sizeof(float));
    B = (float*)malloc(N*sizeof(float));
    X = (float*)malloc(N*sizeof(float));
    
    /* Initialize A and B */
    if (myid == 0) {
        initialize_inputs();
        
        /* Print input matrices */
        print_inputs();
    }
    /* Gaussian Elimination */
    gauss();
    /* Back substitution */
    if (myid == 0) {
        int row, col;
        for (row = N - 1; row >= 0; row--) {
            X[row] = B[row];
            for (col = N-1; col > row; col--) {
                X[row] -= A[row*N + col] * X[col];
            }
            X[row] /= A[row * N + row];
        }
        /* Display output */
        print_X();
    }
    free(A);
    free(B);
    free(X);
    MPI_Finalize();
    return 0;
}
int main(int argc, char **argv) {

  
  

  /* Gaussian Elimination */
    int         my_rank;   /* My process rank           */

    int         p;         /* The number of processes   */
	
	int         norm;      /* The number of rows        */

                           /* calculated	            */

    int         row;       /* Row number                */

    int         col;       /* Column number             */
	
    int         source;    /* Process sending integral  */

    int         dest = 0;  /* All messages go to 0      */

    int         tag = 0;
	

    MPI_Status  status;
	
	void Get_data(int my_rank, int p);

    void Compute(int norm, int my_rank, int p);   
	
	MPI_Init(&argc, &argv);
	
    /* Get my process rank */

    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    /* Find out how many processes are being used */

    MPI_Comm_size(MPI_COMM_WORLD, &p);
        
    /* Timing variables */
    double starttime = 0.0;
    double endtime = 0.0;
	
	
    printf("Computing Parallel via MPI.\n");
	
	
	if (my_rank == 0) {
      
	    /* Start Clock */
        printf("\nStarting clock.\n");
	
        starttime = MPI_Wtime();
	
	    /* Broadcast the value of N to all nodes */
     	MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD);
  


      /* Initialize A and B */
      initialize_inputs();

      /* Print input matrices */
      print_inputs();
  
  

  } else
  
	    /* Receive the broadcast N value */	
     	MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD);

    /* Updating needed data in correspoding row of A and B for each process */
	
    Send_data(my_rank, p);
	
	/* Gauss elimination */
	for (norm = 0; norm < N - 1; norm++) {
	  int i;
	  for (i = norm; i < N; i++) {
	    MPI_Bcast(A[i], N, MPI_FLOAT, i%p, MPI_COMM_WORLD);
		MPI_Bcast(&B[i], 1, MPI_FLOAT, i%p, MPI_COMM_WORLD);
	  }
	  
	  Compute(norm, my_rank, p);
	  
	  MPI_Barrier(MPI_COMM_WORLD);
	  
	}
	
	MPI_Bcast(A[N-1], N, MPI_FLOAT, (N-1)%p, MPI_COMM_WORLD);
    MPI_Bcast(&B[N-1], 1, MPI_FLOAT, (N-1)%p, MPI_COMM_WORLD);
	
	if (my_rank == 0) {
	
	    int row, col;

        /* Back substitution */
		
		for (row = N - 1; row >= 0; row--) {
          X[row] = B[row];
          for (col = N-1; col > row; col--) {
            X[row] -= A[row][col] * X[col];
          }
          X[row] /= A[row][row];
        }

    
  
    /* Stop Clock */
	
    endtime = MPI_Wtime();
	
    /* Display timing results */
	
    printf("That tooks %f seconds.\n", endtime-starttime);  

    /* Display output */
    print_X();
	
  }
	
  /* Shut down MPI */

  MPI_Finalize();

  exit(0);
}
示例#8
0
void main(int argc, char **argv)
{
/*               Elapsed times using <gettimeofday()>.                */
 struct timeval etstart, etstop;
 struct timezone tzdummy;
 clock_t etstartt, etstoptt;

/*                 Elapsed times using <times()>.                     */
 unsigned long usecstart, usecstop;

/*                  CPU times for the threads.                        */
 struct tms cputstart, cputstop;

 int row, col;


 parameters(argc, argv);
 initialise_inputs();
 print_inputs();

 CurrentRow = Norm+1;
 Count = NumThreads-1;

 printf("Starting clock ...\n");
 gettimeofday(&etstart, &tzdummy);
 etstartt = times(&cputstart);

 create_threads();

 wait_for_threads();

/*
 * Diagonal elements are not normalised to 1.
 * This is treated in back substitution.
 */

/*                         Back substitution.                         */
 for (row = N-1; row >= 0; row--)
 {
  X[row] = B[row];
  for (col = N-1; col > row; col--)
  X[row] -= A[row][col]*X[col];
  X[row] /= A[row][row];
  }

 gettimeofday(&etstop, &tzdummy);
 etstoptt = times(&cputstop);
 printf("Stopped clock.\n");
 
 usecstart = (unsigned long)etstart.tv_sec*1000000+etstart.tv_usec;
 usecstop = (unsigned long)etstop.tv_sec*1000000+etstop.tv_usec;

 print_X();

 printf("Elapsed time = %g ms.\n", 
(float)(usecstop-usecstart)/(float)1000);

 printf("Elapsed time according to <times()> = %g ms.\n", 
(etstoptt-etstartt)/(float)CLK_TCK*1000);

 printf("CPU times are accurate to the nearest %g ms.\n", 
1.0/(float)CLK_TCK*1000.0);

 printf("The total CPU time for parent = %g ms.\n", 
(float)((cputstop.tms_utime+cputstop.tms_stime)-
(cputstart.tms_utime+cputstart.tms_stime))/(float)CLK_TCK*1000);

 printf("The system CPU time for parent = %g ms.\n", 
(float)(cputstop.tms_stime-cputstart.tms_stime)/(float)CLK_TCK*1000);
 }