#include "mpi.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define MIN(a, b) ((a)<(b)?(a):(b))
int main(int argc, char *argv[]) {
int count; /* Local prime count */
double elapsed_time; /* Parallel execution time */
int first; /* Index of first multiple */
int global_count; /* Global prime count */
int high_value; /* Highest value on this proc */
int i;
int id; /* Process ID number */
int index; /* Index of current prime */
int low_value; /* Lowest value on this proc */
char *marked; /* Portion of 2,...,'n' */
int n; /* Sieving from 2, ..., 'n' */
int p; /* Number of processes */
int proc0_size; /* Size of proc 0's subarray */
int prime; /* Current prime */
int size; /* Elements in 'marked' */
//Init,MPI 程序启动时“自动”建立两个通信器:MPI_COMM_WORLD:包含程序中所有 MPI 进
程,MPI_COMM_SELF:有单个进程独自构成,仅包含自己
MPI_Init(&argc, &argv);
/* Start the timer */
//MPI_COMM_RANK 得到本进程的进程号,进程号取值范围为 0, …, np-1
MPI_Comm_rank(MPI_COMM_WORLD, &id);
// MPI_COMM_SIZE 得到所有参加运算的进程的个数
MPI_Comm_size(MPI_COMM_WORL D, &p);
// MPI_Barrier 是 MPI 中的一个函数接口,表示阻止调用直到 communicator 中所有进程完成
调用
MPI_Barrier(MPI_COMM_WORLD);
//表示从过去某一时刻到调用时刻所经历的时间