myBcast.h
资源名称:myBcast.zip [点击查看]
上传用户:xhsolar213
上传日期:2022-08-01
资源大小:1k
文件大小:1k
源码类别:
并行计算
开发平台:
C/C++
- /*--------------------------------------------------------------------------------
- --- Calculo paralelo ---
- --- Licenciatura en Bioinformatica ---
- --- Alumno: German Gonzalez ---
- ----------------------------------------------------------------------------------*/
- #include <vector>
- using namespace std;
- double myBcast(vector <int> &v, int &n, int numprocs, int myrank)
- {
- int n1=0, n2=numprocs;
- double starttime, endtime, time;
- MPI_Status status;
- MPI_Barrier(MPI_COMM_WORLD); //Barrera
- starttime = MPI_Wtime(); //Empiezo a medir el tiempo
- while (n2-n1>1)
- {
- int middle = (n1+n2)/2;
- if (myrank==n1)
- MPI_Send(&v.at(0), n, MPI_INT,middle, 1, MPI_COMM_WORLD);
- else if (myrank==middle)
- {
- v.resize(n);
- MPI_Recv(&v.at(0), n, MPI_INT, n1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
- }
- if (myrank<middle) n2 = middle;
- else n1=middle;
- }
- MPI_Barrier(MPI_COMM_WORLD); //Barrera
- endtime = MPI_Wtime(); //Termino de medir el tiempo
- time = endtime-starttime;
- return time;
- }