Skip to content

Commit d9a3aec

Browse files
author
jack.poulson
committed
Committing current copy of PMRRR, version 0.6.
0 parents  commit d9a3aec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+17476
-0
lines changed

EXAMPLES/C/Makefile

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CC = mpicc
2+
LD = mpicc
3+
4+
CFLAGS = -Wall -g -pthread
5+
LDFLAGS = -D_THREAD_SAFE=1 -pthread
6+
7+
# Additional compiler flags for MPI Implementation
8+
# Most MPI Implementations do not require additional
9+
# flags, but e.g. Intel's MPI requieres
10+
# the flag '-mt_mpi' to link to a MPI supporting
11+
# multithreading
12+
MPIFLAGS =
13+
14+
INCPATH = ../../INCLUDE
15+
LIBPATH = ../../LIB
16+
LIBS = pmrrr gfortran m pthread rt
17+
18+
19+
######################## do not edit below ###########################
20+
21+
22+
CFLAGS += $(MPIFLAGS) -I$(INCPATH)
23+
LDFLAGS += $(MPIFLAGS) -I$(INCPATH)
24+
25+
.PHONY: all
26+
27+
all: main_all.x main_ind.x main_val.x
28+
29+
# All eigenpairs
30+
main_all.x: main_all.o
31+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
32+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
33+
34+
main_all.o: main_all.c
35+
36+
# Subset of eigenpairs by index
37+
main_ind.x: main_ind.o
38+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
39+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
40+
41+
main_ind.o: main_ind.c
42+
43+
# Subset of eigenpairs by value
44+
main_val.x: main_val.o
45+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
46+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
47+
48+
main_val.o: main_val.c
49+
50+
.PHONY: clean
51+
clean:
52+
rm -f main_*.x core.* *__genmod.* *.o *~

EXAMPLES/C/Makefile.gnu.jugene

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CC = mpicc
2+
LD = mpicc
3+
4+
CFLAGS = -Wall -g -pthread
5+
LDFLAGS = -D_THREAD_SAFE=1 -pthread
6+
7+
# Additional compiler flags for MPI Implementation
8+
# Most MPI Implementations do not require additional
9+
# flags, but e.g. Intel's MPI requieres
10+
# the flag '-mt_mpi' to link to a MPI supporting
11+
# multithreading
12+
MPIFLAGS =
13+
14+
INCPATH = ../../INCLUDE
15+
LIBPATH = ../../LIB
16+
LIBS = pmrrr gfortran m pthread rt
17+
18+
19+
######################## do not edit below ###########################
20+
21+
22+
CFLAGS += $(MPIFLAGS) -I$(INCPATH)
23+
LDFLAGS += $(MPIFLAGS) -I$(INCPATH)
24+
25+
.PHONY: all
26+
27+
all: main_all.x main_ind.x main_val.x
28+
29+
# All eigenpairs
30+
main_all.x: main_all.o
31+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
32+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
33+
34+
main_all.o: main_all.c
35+
36+
# Subset of eigenpairs by index
37+
main_ind.x: main_ind.o
38+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
39+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
40+
41+
main_ind.o: main_ind.c
42+
43+
# Subset of eigenpairs by value
44+
main_val.x: main_val.o
45+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
46+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
47+
48+
main_val.o: main_val.c
49+
50+
.PHONY: clean
51+
clean:
52+
rm -f main_*.x core.* *__genmod.* *.o *~

EXAMPLES/C/Makefile.ibm.jugene

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CC = mpixlc_r
2+
LD = mpixlc_r
3+
4+
CFLAGS = -qthreaded -qstrict -qarch=450 -qtune=450
5+
LDFLAGS = -qthreaded -qstrict -qarch=450 -qtune=450
6+
7+
# Additional compiler flags for MPI Implementation
8+
# Most MPI Implementations do not require additional
9+
# flags, but e.g. Intel's MPI requieres
10+
# the flag '-mt_mpi' to link to a MPI supporting
11+
# multithreading
12+
MPIFLAGS =
13+
14+
INCPATH = ../../INCLUDE
15+
LIBPATH = ../../LIB /bgsys/local/lib /opt/ibmcmp/xlf/bg/11.1/lib /opt/ibmcmp/xlsmp/bg/1.7/lib
16+
LIBS = pmrrr esslbg m xl xlopt xlf90_r xlfmath xlsmp pthread rt
17+
18+
19+
######################## do not edit below ###########################
20+
21+
22+
CFLAGS += $(MPIFLAGS) -I$(INCPATH)
23+
LDFLAGS += $(MPIFLAGS) -I$(INCPATH)
24+
25+
.PHONY: all
26+
27+
all: main_all.x main_ind.x main_val.x
28+
29+
# All eigenpairs
30+
main_all.x: main_all.o
31+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
32+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
33+
34+
main_all.o: main_all.c
35+
36+
# Subset of eigenpairs by index
37+
main_ind.x: main_ind.o
38+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
39+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
40+
41+
main_ind.o: main_ind.c
42+
43+
# Subset of eigenpairs by value
44+
main_val.x: main_val.o
45+
$(LD) $(LDFLAGS) $< $(foreach LIBP,$(LIBPATH),-L$(LIBP)) \
46+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
47+
48+
main_val.o: main_val.c
49+
50+
.PHONY: clean
51+
clean:
52+
rm -f main_*.x core.* *__genmod.* *.o *~

EXAMPLES/C/Makefile.intel

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CC = mpiicc
2+
LD = mpiicc
3+
4+
CFLAGS = -Wall -g -pthread
5+
LDFLAGS = -D_THREAD_SAFE=1 -pthread
6+
7+
# Additional compiler flags for MPI Implementation
8+
# Most MPI Implementations do not require additional
9+
# flags, but e.g. Intel's MPI requieres
10+
# the flag '-mt_mpi' to link to a MPI supporting
11+
# multithreading
12+
MPIFLAGS = -mt_mpi
13+
14+
INCPATH = ../../INCLUDE
15+
LIBPATH = ../../LIB
16+
LIBS = pmrrr ifcore pthread rt imf m
17+
18+
19+
######################## do not edit below ###########################
20+
21+
22+
CFLAGS += $(MPIFLAGS) -I$(INCPATH)
23+
LDFLAGS += $(MPIFLAGS) -I$(INCPATH)
24+
25+
.PHONY: all
26+
27+
all: main_all.x main_ind.x main_val.x
28+
29+
# All eigenpairs
30+
main_all.x: main_all.o
31+
$(LD) $(LDFLAGS) $< -L$(LIBPATH) \
32+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
33+
34+
main_all.o: main_all.c
35+
36+
# Subset of eigenpairs by index
37+
main_ind.x: main_ind.o
38+
$(LD) $(LDFLAGS) $< -L$(LIBPATH) \
39+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
40+
41+
main_ind.o: main_ind.c
42+
43+
# Subset of eigenpairs by value
44+
main_val.x: main_val.o
45+
$(LD) $(LDFLAGS) $< -L$(LIBPATH) \
46+
$(foreach LIBRARY,$(LIBS),-l$(LIBRARY)) -o $@
47+
48+
main_val.o: main_val.c
49+
50+
.PHONY: clean
51+
clean:
52+
rm -f main_*.x core.* *__genmod.* *.o *~

EXAMPLES/C/Wilkinson21.data

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
21
2+
1.00000000000000000e+01 1.00000000000000000e+00
3+
9.00000000000000000e+00 1.00000000000000000e+00
4+
8.00000000000000000e+00 1.00000000000000000e+00
5+
7.00000000000000000e+00 1.00000000000000000e+00
6+
6.00000000000000000e+00 1.00000000000000000e+00
7+
5.00000000000000000e+00 1.00000000000000000e+00
8+
4.00000000000000000e+00 1.00000000000000000e+00
9+
3.00000000000000000e+00 1.00000000000000000e+00
10+
2.00000000000000000e+00 1.00000000000000000e+00
11+
1.00000000000000000e+00 1.00000000000000000e+00
12+
0.00000000000000000e+00 1.00000000000000000e+00
13+
1.00000000000000000e+00 1.00000000000000000e+00
14+
2.00000000000000000e+00 1.00000000000000000e+00
15+
3.00000000000000000e+00 1.00000000000000000e+00
16+
4.00000000000000000e+00 1.00000000000000000e+00
17+
5.00000000000000000e+00 1.00000000000000000e+00
18+
6.00000000000000000e+00 1.00000000000000000e+00
19+
7.00000000000000000e+00 1.00000000000000000e+00
20+
8.00000000000000000e+00 1.00000000000000000e+00
21+
9.00000000000000000e+00 1.00000000000000000e+00
22+
1.00000000000000000e+01 0.00000000000000000e+00

EXAMPLES/C/main_all.c

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Example file for using PMRRR to compute all eigenpairs.
3+
* Example run: mpiexec -np 4 -env PMR_NUM_THREADS 2 ./main_all.x
4+
*
5+
*/
6+
7+
#include <stdlib.h>
8+
#include <stdio.h>
9+
#include <string.h>
10+
#include <math.h> /* ceil */
11+
#include <assert.h>
12+
#include "mpi.h"
13+
#include "pmrrr.h"
14+
15+
static int read_tri_mat(char*, double**, double**);
16+
static void print_vector(char*, double*, char*, int);
17+
static void print_matrix(char*, double*, int, int, int);
18+
19+
20+
int main(int argc, char **argv)
21+
{
22+
/* Input parameter to 'pmrrr' */
23+
int n; /* Matrix size */
24+
int il, iu;
25+
int tryRAC = 1; /* Try high rel. accuracy */
26+
double *D, *E; /* Diagonal and off-diagonal elements */
27+
double vl, vu;
28+
29+
double *W; /* eigenvalues */
30+
int nz; /* # local eigenvectors */
31+
int offset;
32+
double *Z; /* eigenvectors; stored by colums */
33+
int ldz;
34+
int *Zsupp; /* eigenvector support */
35+
36+
/* Others */
37+
int pid, nproc, info, status;
38+
int i;
39+
40+
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &status);
41+
MPI_Comm_rank(MPI_COMM_WORLD, &pid);
42+
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
43+
44+
/* Read in data from file, space for D and E will
45+
* be allocated and needs to be freed at the end */
46+
n = read_tri_mat("./Wilkinson21.data", &D, &E);
47+
48+
/* Print input */
49+
if (pid == 0) {
50+
printf("\n%% Input matrix:\n\n");
51+
printf("n = %d;\n", n);
52+
print_vector("D=[", D, "];", n );
53+
print_vector("E=[", E, "];", n-1);
54+
}
55+
56+
/* Allocate memory */
57+
W = (double *) malloc( n * sizeof(double) );
58+
Zsupp = (int *) malloc( 2*n * sizeof(int) );
59+
60+
nz = (int) ceil(n / (double) nproc);
61+
ldz = n;
62+
63+
Z = (double *) malloc((size_t) n * nz * sizeof(double) );
64+
65+
/* Use MRRR to compute eigenvalues and -vectors */
66+
info = pmrrr("Vectors", "All", &n, D, E, &vl, &vu, &il,
67+
&iu, &tryRAC, MPI_COMM_WORLD, &nz, &offset,
68+
W, Z, &ldz, Zsupp);
69+
assert(info == 0);
70+
71+
/* Possibly communicate eigenvalues */
72+
/* PMR_comm_eigvals(MPI_COMM_WORLD, &nz, &offset, W); */
73+
74+
/* Print results */
75+
for (i=0; i<nproc; i++) {
76+
MPI_Barrier(MPI_COMM_WORLD);
77+
if (i == pid) {
78+
printf("\n\n%% Results of process %d:\n", pid);
79+
if (i == 0) printf("W = [];");
80+
print_vector("W = [W;", W, "];", nz);
81+
print_matrix("Z", Z, n, nz, offset);
82+
fflush(stdout);
83+
}
84+
}
85+
86+
/* Free allocated memory */
87+
free(D);
88+
free(E);
89+
free(W);
90+
free(Z);
91+
free(Zsupp);
92+
93+
MPI_Finalize();
94+
95+
return(0);
96+
}
97+
98+
99+
100+
101+
/*
102+
* Reads the triadiagonal matrix from a file.
103+
*/
104+
static int read_tri_mat(char *filename, double **Dp, double **Ep)
105+
{
106+
int i, n;
107+
FILE *filedes;
108+
109+
filedes = fopen(filename, "r");
110+
assert(filedes != NULL);
111+
112+
fscanf(filedes, "%d", &n);
113+
114+
*Dp = (double *) malloc( n * sizeof(double) );
115+
assert(*Dp != NULL);
116+
117+
*Ep = (double *) malloc( n * sizeof(double) );
118+
assert(*Ep != NULL);
119+
120+
for (i=0; i<n; i++) {
121+
fscanf(filedes, "%le %le", *Dp+i, *Ep+i);
122+
}
123+
(*Ep)[n-1] = 0.0;
124+
125+
fclose(filedes);
126+
127+
return(n);
128+
}
129+
130+
131+
132+
static void print_vector(char *pre, double *v, char *post, int n)
133+
{
134+
int i;
135+
136+
printf("\n%s\n", pre);
137+
for (i=0; i<n; i++) {
138+
printf("%.17e", v[i]);
139+
printf("\n");
140+
}
141+
printf("%s\n", post);
142+
}
143+
144+
145+
146+
static void print_matrix(char *name, double *A, int lda,
147+
int numcols, int offset)
148+
{
149+
int j;
150+
char str1[20], str2[20];
151+
152+
for (j=1; j<=numcols; j++) {
153+
str1[0] = '\0';
154+
strcat(str1,name);
155+
strcat(str1,"(:,");
156+
sprintf(str2, "%d",j+offset);
157+
strcat(str1, str2);
158+
strcat(str1, ")=[");
159+
print_vector(str1, &A[(j-1)*lda],"];", lda);
160+
}
161+
}

0 commit comments

Comments
 (0)