forked from thesiddharth/dpsvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpi_sample.cpp
More file actions
47 lines (32 loc) · 798 Bytes
/
mpi_sample.cpp
File metadata and controls
47 lines (32 loc) · 798 Bytes
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
#include <stdio.h>
#include <mpi.h>
#include <cblas.h>
float m[] = {
3, 1, 3,
1, 5, 9,
2, 6, 5
};
float x[] = {
-1, -1, 1
};
float y[] = {
0, 0, 0
};
int main(int argc, char *argv[]) {
int numprocs, rank, namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Get_processor_name(processor_name, &namelen);
printf("Process %d on %s out of %d\n", rank, processor_name, numprocs);
int i, j;
for (i=0; i<3; ++i) {
for (j=0;j<3; ++j) printf("%5.1f", m[i*3+j]);
putchar('\n');
}
cblas_sgemv(CblasRowMajor, CblasNoTrans, 3, 3, 1.0, m, 3, x, 1, 0.0, y, 1);
for (i=0; i<3; ++i) printf("%5.1f\n", y[i]);
MPI_Finalize();
return 0;
}