I have a list of words, my goal is to match each word in a very very long phrase. I'm having no problem in matching each word, my only problem is to return a vector of structures containing informations about each match.
In code:
typedef struct {
int A, B, C; } Match;
__global__ void Find(veryLongPhrase * _phrase, Words * _word_list, vector<Match> * _matches)
{
int a, b, c;
[...] //Parallel search for each word in the phrase
if(match) //When an occurrence is found
{
_matches.push_back(new Match{ A = a, B = b, C = c }); //Here comes the unknown, what should I do here???
}
}
main()
{
[...]
veryLongPhrase * myPhrase = "The quick brown fox jumps over the lazy dog etc etc etc..."
Words * wordList = {"the", "lazy"};
vector<Match> * matches; //Obviously I can't pass a vector to a kernel
Find<<< X, Y >>>(myPhrase, wordList, matches);
[...]
}
I have tried Thrust library but without any success, can you suggest me any kind of solution?
Thank you very much.
something like this should work (coded in browser, not tested):
This will require compute capability 1.1 or better for the atomic operation.
Here's a worked example:
Note that in this case my
Match
result struct creation is different, and I am passing by reference, but the concept is the same.