So I am in a basic High School coding class. We had to think up one of our semester projects. I chose to base mine on ideas and applications that arn't used in traditional code. This brought up the idea for use of CUDA. One of the best ways I would know to compare speed of traditional methods versus unconventional is string generation and comparison. One could demonstrate the generation and matching speed of traditional CPU generation with timers and output. And then you could show the increase(or decrease) in speed and output of GPU Processing.
I wrote this C++ code to generate random characters that are input into a character array and then match that array to a predetermined string. However like most CPU programming it is incredibly slow comparatively to GPU programming. I've looked over CUDA API and could not find something that would possibly lead me in the right direction for what I'm looking to do.
Below is the code I have written in C++, if anyone could point me in the direction of such things as a random number generator that I can convert to chars using ASCII codes, that would be excellent.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int sLength = 0;
int count = 0;
int stop = 0;
int maxValue = 0;
string inString = "aB1@";
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength = sizeof(alphanum) - 1;
char genRandom()
{
return alphanum[rand() % stringLength];
}
int main()
{
cout << "Length of string to match?" << endl;
cin >> sLength;
string sMatch(sLength, ' ');
while(true)
{
for (int x = 0; x < sLength; x++)
{
sMatch[x] = genRandom();
//cout << sMatch[x];
count++;
if (count == 2147000000)
{
count == 0;
maxValue++;
}
}
if (sMatch == inString)
{
cout << "It took " << count + (maxValue*2147000000) << " randomly generated characters to match the strings." << endl;
cin >> stop;
}
//cout << endl;
}
}