-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added working example of matrix mult using amrex table2D interface to…
… cublas, but getting right ans for wrong reasons
- Loading branch information
1 parent
d1b30a1
commit 2f2f388
Showing
6 changed files
with
154 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef GLOBAL_FUNCS_H_ | ||
#define GLOBAL_FUNCS_H_ | ||
|
||
#include <AMReX_GpuUtility.H> | ||
|
||
#include <iomanip> | ||
#include <string> | ||
|
||
#include "MatrixDef.H" | ||
|
||
template<typename U, typename V> | ||
void | ||
Define_Table2D (U& Tab2D_data, V val) | ||
{ | ||
auto tlo = Tab2D_data.lo(); | ||
auto thi = Tab2D_data.hi(); | ||
|
||
auto const& Tab2D = Tab2D_data.table(); | ||
|
||
for (int i = tlo[0]; i < thi[0]; ++i) | ||
{ | ||
for (int j = tlo[1]; j < thi[1]; ++j) //slow access | ||
{ | ||
ComplexType new_val(val.real()*(j+1), val.imag()*(j+1)); | ||
|
||
Tab2D(i,j) = new_val; | ||
} | ||
} | ||
} | ||
|
||
|
||
template<typename U, typename V> | ||
void | ||
SetVal_Table2D (U& Tab2D_data, V val) | ||
{ | ||
auto tlo = Tab2D_data.lo(); | ||
auto thi = Tab2D_data.hi(); | ||
|
||
auto const& Tab2D = Tab2D_data.table(); | ||
|
||
for (int i = tlo[0]; i < thi[0]; ++i) | ||
{ | ||
for (int j = tlo[1]; j < thi[1]; ++j) //slow access | ||
{ | ||
Tab2D(i,j) = val; | ||
} | ||
} | ||
} | ||
|
||
template<typename U> | ||
void Print_Table2D(const U& Tab2D_data, const std::string tablename="") | ||
{ | ||
auto tlo = Tab2D_data.lo(); | ||
auto thi = Tab2D_data.hi(); | ||
|
||
auto const& Tab2D = Tab2D_data.table(); | ||
|
||
std::cout << "\nPrinting Table: " << tablename << "\n"; | ||
for (int i = tlo[0]; i < thi[0]; ++i) | ||
{ | ||
for (int j = tlo[1]; j < thi[1]; ++j) //slow access | ||
{ | ||
std::cout << std::setw(12) << std::setprecision(6) << std::fixed | ||
<< Tab2D(i,j).real() << " + " | ||
<< Tab2D(i,j).imag() << "i"; | ||
|
||
if (j < thi[1] - 1) std::cout << ", "; | ||
} | ||
std::cout << "\n"; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#include <AMReX_REAL.H> | ||
#include "MatrixDef.H" | ||
|
||
namespace MathLib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,11 @@ | ||
#ifndef MATRIX_DEF_H_ | ||
#define MATRIX_DEF_H_ | ||
|
||
#include <AMReX_GpuComplex.H> | ||
#include <AMReX_REAL.H> | ||
#include<AMReX_TableData.H> | ||
#include <AMReX_GpuUtility.H> | ||
#include <AMReX_REAL.H> | ||
|
||
using ComplexType = amrex::GpuComplex<amrex::Real>; | ||
using Matrix2D = amrex::TableData<ComplexType, 2>; | ||
|
||
template<typename U, typename V> | ||
void | ||
SetVal_Table2D (U& Tab2D_data, V val) | ||
{ | ||
auto tlo = Tab2D_data.lo(); | ||
auto thi = Tab2D_data.hi(); | ||
|
||
auto const& Tab2D = Tab2D_data.table(); | ||
|
||
for (int i = tlo[0]; i < thi[0]; ++i) | ||
{ | ||
for (int j = tlo[1]; j < thi[1]; ++j) //slow moving index. printing slow | ||
{ | ||
Tab2D(i,j) = val; | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters