-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTarea.cpp
More file actions
65 lines (46 loc) · 1.1 KB
/
STarea.cpp
File metadata and controls
65 lines (46 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include "mpi.h"
int main(int argc, char **argv)
{
int i, ii;
double sum;
int pid, np;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &pid);
MPI_Comm_size(MPI_COMM_WORLD, &np);
int N;
double p = 0.0 ;
if (0 == pid) {
std::printf("Por favor escriba el tamaño del arreglo:\n");
std::scanf("%d", &N);
std::printf("%d\n", N);
std::printf("Por favor escriba el valor de p:\n");
std::printf("%lf", &p);
std::printf("%d\n", p);
}
MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&p, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
double * V = new double [N];
int npros = N/np;
int imin = pid*npros;
for ( i = imin; i < imin + npros; ++i) {
V[i] = 2*i;
}
for ( ii = imin; ii < imin + npros; ++ii) {
sum += std::pow(V[ii],p);
}
double total = 0;
MPI_Reduce(&sum, &total, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
if (0 == pid) {
double ftotal = 0;
ftotal = std::pow(total, 1.0 / p);
std::printf("La norma p es %lf\n", ftotal);
}
delete [] V;
MPI_Finalize();
return 0;
}
*/