Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include "mpi.h"
- #include <time.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main(argc,argv)
- int argc;
- char *argv[];
- {
- int i,myid, numprocs;
- int source,count;
- MPI_Status status;
- MPI_Request request;
- double start_time, end_time;
- MPI_Init(&argc,&argv);
- MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
- MPI_Comm_rank(MPI_COMM_WORLD,&myid);
- source=0;
- if (argc < 2){
- printf("Specify data size");
- MPI_Finalize();
- }
- sscanf(argv[1], "%d", &count);
- double *buffer = (double *)malloc(sizeof(double) * count);
- if(myid == source){
- int i;
- srand(0xBEEF);
- for (i=0; i<count; i++){
- buffer[i]=rand();
- }
- start_time = MPI_Wtime();
- }
- MPI_Barrier(MPI_COMM_WORLD);
- for(int j=0; j<myid; j++){
- int root=j;
- MPI_Bcast(buffer,count,MPI_INT,root,MPI_COMM_WORLD);
- for(int k=0; k<1000000; k++){
- ;
- }
- MPI_Barrier(MPI_COMM_WORLD);
- }
- if (myid == 0){
- end_time = MPI_Wtime();
- printf("Elapsed time: %.8f\n", end_time-start_time);
- }
- MPI_Finalize();
- }
Add Comment
Please, Sign In to add comment