Will multi threading provide any performance boost?

前端 未结 19 825
说谎
说谎 2021-02-05 13:49

I am new to programming in general so please keep that in mind when you answer my question.

I have a program that takes a large 3D array (1 billion elements) and sums up

19条回答
  •  深忆病人
    2021-02-05 13:59

    Try this code:

    int dim = 1000;
    int steps = 7 //ranges from 1 to  255
    
    for (int stage = 1; stage < steps; stage++)
    for (int k = 0; k < dim; k++)
        for (int i = 0; i < dim; i++)
        {
                sum = 0;
                for (int j = 0; j < dim; j++)
                        if (partMap[(((i * dim) + k) * dim) + j] >= stage)
                                projection[i*dim + j] ++ ;
                                // changed order of i and j
        }
    
    
    transponse(projection)
    

    I changed the order of loops to make the code cache friendly... You would gain with it an order of magninute performance boost... Be shure.

    This is the step you should do before you try to run into multithreading

提交回复
热议问题