Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cuda_runtime.h"
- #include "device_launch_parameters.h"
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <ctime>
- #include <stdio.h>
- using namespace std;
- const short L = 4;
- __global__ void mulMat(int Reg[L][L], int Q[L])
- {
- int i = blockIdx.x;
- int newQ[L];
- int temp = 0;
- for (int j = 0; j < L; j++) {
- temp += Reg[i][j] * Q[j];
- }
- newQ[i] = temp % 2;
- Q[i] = newQ[i];
- }
- int main()
- {
- const clock_t begin_time = clock();
- int Register[L][L] = { {0,0,0,1}, {1,1,1,0}, {0,1,1,0}, {0,0,1,1} };
- int Q[L] = { 1,0,0,0 };
- //int newQ[L];
- bool* tab = new bool[(int)pow(2, L) - 1];
- bool isMax = true;
- int dec;
- for (int i = 0; i < pow(2, L); i++) {
- tab[i] = false;
- }
- for (int i = 0; i < L; i++) {
- for (int j = 0; j < L; j++)
- {
- cout << Register[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- dec = 0;
- for (int i = 0; i < L; i++) {
- dec += Q[L - i - 1] * pow(2, L - i - 1);
- cout << Q[i] << " ";
- }
- cout << " decimal: " << dec << endl;
- int(*aReg)[L];
- int(*aQ);
- int(*aDec);
- cudaMalloc((void**)&aReg, (L * L) * sizeof(int));
- cudaMalloc((void**)&aQ, L * sizeof(int));
- cudaMemcpy(aReg, Register, (L * L) * sizeof(int), cudaMemcpyHostToDevice);
- cudaMemcpy(aQ, Q, L * sizeof(int), cudaMemcpyHostToDevice);
- for (int k = 0; k < pow(2, L) - 1; k++) {
- mulMat << <L, 1 >> > (aReg, aQ);
- cudaMemcpy(Q, aQ, L * sizeof(int), cudaMemcpyDeviceToHost);
- dec = 0;
- for (int i = 0; i < L; i++) {
- dec += Q[i] * pow(2, i);
- cout << Q[i] << " ";
- }
- cout << " decimal: " << dec << endl;
- if (!tab[dec]) {
- tab[dec] = true;
- }
- else {
- isMax = false;
- break;
- }
- }
- cudaFree(aReg);
- cudaFree(aQ);
- if (isMax) {
- cout << "CYKL MAKSYMALNY";
- }
- else {
- cout << "CYKL NIEMAKSYMALNY";
- }
- cout << endl;
- cout << float(clock() - begin_time) / CLOCKS_PER_SEC;
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement