20 int lens_u[] = {n, n, n};
29 for (
int a=0;
a<3;
a++){
31 for (
int b=0;
b<3;
b++){
39 for (
int a=0;
a<3;
a++){
44 double st_time = MPI_Wtime();
46 w[0][
"ijk"] = D[
"kl"]*u[
"ijl"];
47 w[1][
"ijk"] = D[
"jl"]*u[
"ilk"];
48 w[2][
"ijk"] = D[
"il"]*u[
"ljk"];
50 for (
int a=0;
a<3;
a++){
51 for (
int b=0;
b<3;
b++){
52 z[
a][
"ijk"] += G[
a][
b][
"ijk"]*w[
b][
"ijk"];
56 u[
"ijk"] = D[
"lk"]*z[0][
"ijl"];
57 u[
"ijk"] += D[
"lj"]*z[1][
"ilk"];
58 u[
"ijk"] += D[
"li"]*z[2][
"ljk"];
60 double exe_time = MPI_Wtime() - st_time;
62 bool pass = u.
norm2() >= 1.E-6;
64 for (
int a=0;
a<3;
a++){
73 printf(
"{ Spectral element method } passed \n");
75 printf(
"{ spectral element method } failed \n");
77 printf(
"Spectral element method on %d*%d*%d grid with %d processors took %lf seconds\n", n,n,n,dw.
np,exe_time);
88 char ** itr = std::find(begin, end, option);
89 if (itr != end && ++itr != end){
96 int main(
int argc,
char ** argv){
98 int const in_num = argc;
99 char ** input_str = argv;
101 MPI_Init(&argc, &argv);
102 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
103 MPI_Comm_size(MPI_COMM_WORLD, &np);
106 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
111 World dw(argc, argv);
114 printf(
"Running 3D spectral element method with %d*%d*%d grid\n",n,n,n);
Matrix class which encapsulates a 2D tensor.
an instance of the CTF library (world) on a MPI communicator
dtype norm2()
computes the frobenius norm of the tensor (needs sqrt()!)
void fill_random(dtype rmin, dtype rmax)
fills local unique tensor elements to random values in the range [min,max] works only for dtype in {f...
int rank
rank of local processor
char * getCmdOption(char **begin, char **end, const std::string &option)
an instance of a tensor within a CTF world
int main(int argc, char **argv)
int np
number of processors
int spectral(int n, World &dw)
computes the following kernel of the spectral element method Given u, D, and diagonal matrices G_{xy}...