Skip to content

Commit

Permalink
updated README, add a test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
treefrogframework committed Nov 10, 2024
1 parent 29f11c2 commit 9d0f166
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@main
- name: Homebrew
run: brew install qt6
run: brew install qt6 pkg-config
- name: build
run: |
qmake CONFIG+=release
Expand All @@ -25,6 +25,7 @@ jobs:
./cpi tests/unique_ptr.cpp
./cpi tests/optional.cpp
./cpi tests/if_initializer.cpp
./cpi test/dgemm.cpp
- name: error tests
run: |
./cpi tests/error_code.cpp
Expand All @@ -38,7 +39,7 @@ jobs:
- name: apt
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools
sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config
- name: build
run: |
qmake6 CONFIG+=release
Expand All @@ -53,6 +54,7 @@ jobs:
./cpi tests/if_initializer.cpp
./cpi tests/ranges.cpp
./cpi tests/concept_add.cpp
./cpi test/dgemm.cpp
- name: error tests
run: |
./cpi tests/error_code.cpp
Expand All @@ -66,7 +68,7 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt purge -y gcc g++
sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools
sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config
- name: build
run: |
qmake6 -spec linux-clang CONFIG+=release
Expand All @@ -79,6 +81,7 @@ jobs:
./cpi tests/unique_ptr.cpp
./cpi tests/optional.cpp
./cpi tests/if_initializer.cpp
./cpi test/dgemm.cpp
- name: error tests
run: |
./cpi tests/error_code.cpp
Expand All @@ -91,7 +94,7 @@ jobs:
- name: apt
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools
sudo apt-get install -y --no-install-recommends g++ make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config
- name: build
run: |
qmake6 CONFIG+=release
Expand All @@ -106,6 +109,7 @@ jobs:
./cpi tests/if_initializer.cpp
./cpi tests/ranges.cpp
./cpi tests/concept_add.cpp
./cpi test/dgemm.cpp
- name: error tests
run: |
./cpi tests/error_code.cpp
Expand All @@ -119,7 +123,7 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt purge -y gcc g++
sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools
sudo apt-get install -y --no-install-recommends clang make qmake6 qt6-base-dev qt6-base-dev-tools pkg-config
- name: build
run: |
qmake6 -spec linux-clang CONFIG+=release
Expand All @@ -132,6 +136,7 @@ jobs:
./cpi tests/unique_ptr.cpp
./cpi tests/optional.cpp
./cpi tests/if_initializer.cpp
./cpi test/dgemm.cpp
- name: error tests
run: |
./cpi tests/error_code.cpp
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-relase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
release_name: Cpi version ${{ github.ref }} release
draft: false
prerelease: false

Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,47 @@ int main(int argc, char *argv[])
1.7320
```

Furthermore, pkg-config command can be used for *CompileOptions*.

```cpp
#include <cblas.h>
#include <iostream>

int main()
{
// 2x2 Matrix
int M = 2, N = 2, K = 2;
double A[4] = {1.0, 2.0, 3.0, 4.0};
double B[4] = {5.0, 6.0, 7.0, 8.0};
double C[4];

// General Matrix-Matrix multiplication
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
M, N, K,
1.0, A, K, B, N,
0.0, C, N);

// Print results
std::cout << "Result of A * B = C:" << std::endl;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
std::cout << C[i * 2 + j] << " ";
}
std::cout << std::endl;
}
return 0;
}

// CompileOptions: `pkg-config --cflags --libs openblas`
```

```sh
$ cpi dgemm.cpp
Result of A * B = C:
19 22
43 50
```

#### Running like a scripting language
Adding a shebang, save as *hello.cpps*. No longer compiled in a C++ compiler successfully.

Expand Down
29 changes: 29 additions & 0 deletions tests/dgemm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <cblas.h>
#include <iostream>

int main()
{
// 2x2 Matrix
int M = 2, N = 2, K = 2;
double A[4] = {1.0, 2.0, 3.0, 4.0};
double B[4] = {5.0, 6.0, 7.0, 8.0};
double C[4];

// General Matrix-Matrix multiplication
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
M, N, K,
1.0, A, K, B, N,
0.0, C, N);

// Print results
std::cout << "Result of A * B = C:" << std::endl;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
std::cout << C[i * 2 + j] << " ";
}
std::cout << std::endl;
}
return 0;
}

// CompileOptions: `pkg-config --cflags --libs openblas`

0 comments on commit 9d0f166

Please sign in to comment.