I want to migrate the computationally intensive part (for loop) to the GPU,I hope use cuda,but I can not find similar complete annotated program to refer to,because no previous exposure to this knowledgeplace,I hope to have a more detailed tutorial,place help me.Or there are other methods to accelerate procedures for the following programs?
double wf = 0;
Set<Map.Entry<String, Double>> testWordTFMapSet = testWordTFMap.entrySet();
for (Iterator<Map.Entry<String, Double>> it = testWordTFMapSet.iterator(); it.hasNext(); ) {
Map.Entry<String, Double> me = it.next();
Set<Map.Entry<String, Double>> trainWordTFMapSet = trainWordTFMap.entrySet();
for (Iterator<Map.Entry<String, Double>> it2 = trainWordTFMapSet.iterator(); it2.hasNext(); ) {
Map.Entry<String, Double> me2 = it2.next();
if (me.getKey() == me2.getKey()) {
wf = 1;
} else
wf = computeS.similarity(me.getKey(), me2.getKey(), words);
if (wf > 0.45)
mul += wf * me.getValue() * me2.getValue();
}
}
the calculation of “wf” is another for loop
public static double similarity(String word1, String word2,Map<String, double[]> words) {
double[] count1=words.get(word1);
double[] count2=words.get(word2);
double sum=0;
double Abs1=0;
double Abs2=0;
for (int c = 0; c < count1.length; c++) {
sum += count1[c] * count2[c];
Abs1 += count1[c] * count1[c];
Abs2 += count2[c] * count2[c];
}
return sum / (Abs1 * Abs2);
}