0

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);
}
Amy
  • 43
  • 3
  • YOu can't expect anyone to do your all code here dude – Abrar Jahin Mar 01 '16 at 06:44
  • 1
    Have you profiled your code? Are you sure 6 threads is the optimal size for your `executor`? Have you identified hotspots? We here at SO help people who help themselves, so asking "how do I change my code" is practically guaranteed to not get you what you want. Have you taken any steps to learn about how to possibly run code on the GPU, or do you expect it to be so simple that someone will just kindly write it for you? – Kayaman Mar 01 '16 at 06:46

0 Answers0