Changeset 2230


Ignore:
Timestamp:
Dec 19, 2010, 6:44:37 PM (11 years ago)
Author:
schwittmann
Message:

Improved performance of ExternalClient

Location:
trunk/CrypPlugins/KeySearcher/ExternalClient
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Cryptool.cpp

    r2221 r2230  
    55#include <SDKCommon.hpp>
    66#include <SDKApplication.hpp>
     7
     8#ifdef _OPENMP
     9#include <omp.h>
     10#else
     11#warning No OpenMP support. Expect performance impacts.
     12#endif
    713
    814#define __NO_STD_VECTOR
     
    175181    }
    176182
     183    this->compareLargerThan = j.LargerThen;
     184    this->resultSize = j.ResultSize;
    177185    res.ResultList.resize(j.ResultSize);
    178186    initTop(res.ResultList, j.LargerThen);
     
    229237                throw new std::exception();
    230238        }
    231 
     239#ifdef _OPENMP
     240#pragma omp parallel
     241    {
     242        std::list<std::pair<float, int> > localtop;
     243        int eachChunk = length/omp_get_num_threads();
     244        int from = omp_get_thread_num()*eachChunk;
     245        int to = from + eachChunk;
     246        if(omp_get_thread_num() == omp_get_num_threads()-1)
     247        {
     248            to = length;
     249        }
     250        for(int i=from; i<to; ++i)
     251        {
     252            std::list<std::pair<float, int> >::iterator it = isInTop(localtop, localCosts[i], j.LargerThen);
     253            if (it != localtop.end() || it == localtop.begin())
     254                pushInTop(localtop, it, localCosts[i], i+add);
     255        }
     256        // merge it
     257#pragma omp critical
     258        {
     259            std::list<std::pair<float, int> >::iterator itr;
     260            for(itr = localtop.begin(); itr != localtop.end(); ++itr)
     261            {
     262                std::list<std::pair<float, int> >::iterator posInGlobalList = isInTop(res.ResultList, itr->first, j.LargerThen);
     263                if (posInGlobalList != res.ResultList.end())
     264                    pushInTop(res.ResultList, posInGlobalList, itr->first, itr->second);
     265            }
     266        }
     267    }
     268#else
    232269        //check results:
    233270        for(int i=0; i<length; ++i)
     
    238275                        pushInTop(res.ResultList, it, localCosts[i], i+add);
    239276        }
     277#endif
    240278}
    241279
     
    256294void Cryptool::pushInTop(std::list<std::pair<float, int> >& top, std::list<std::pair<float, int> >::iterator it, float val, int k) {
    257295        top.insert(it, std::pair<float, int>(val, k));
    258         top.pop_back();
     296    if(top.size() > this->resultSize)
     297        top.pop_back();
    259298}
    260299
    261300std::list<std::pair<float, int> >::iterator Cryptool::isInTop(std::list<std::pair<float, int> >& top, float val, bool LargerThen) {
    262         if (LargerThen)
     301    if (top.size() == 0)
     302        return top.begin();
     303
     304        if (LargerThen)
    263305        {
     306                if(top.size() > 0 && val <= top.rbegin()->first)
     307                        return top.end();
    264308                for (std::list<std::pair<float, int> >::iterator k = top.begin(); k != top.end(); k++)
    265309                        if (val > k->first)
     
    268312        else
    269313        {
     314                if(top.size() > 0 && val >= top.rbegin()->first)
     315                        return top.end();
    270316                for (std::list<std::pair<float, int> >::iterator k = top.begin(); k != top.end(); k++)
    271317                        if (val < k->first)
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Cryptool.h

    r2221 r2230  
    1313        cl::Buffer costs;
    1414        float* localCosts;
     15    bool compareLargerThan;
     16    int resultSize;
    1517
    1618        static const int subbatch = 256*256*256;
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Makefile

    r2205 r2230  
    88
    99bin/Cryptool: $(OBJFILES)
    10         g++ -o bin/Cryptool bin/*.o -Wall -Wextra -lpthread -ldl -L/usr/X11R6/lib -lOpenCL -lSDKUtil -L$(SDK)/lib/x86 -L$(SDK)/TempSDKUtil/lib/x86
     10        g++ -fopenmp -O3 -o bin/Cryptool bin/*.o -Wall -Wextra -lpthread -ldl -L/usr/X11R6/lib -lOpenCL -lSDKUtil -L$(SDK)/lib/x86 -L$(SDK)/TempSDKUtil/lib/x86
    1111
    1212bin/%.o: %.cpp
    1313        mkdir -p bin
    14         g++ -msse3 -Wfloat-equal -Wall -Wextra -Wpointer-arith -DATI_OS_LINUX -g3 -ffor-scope -I $(SDK)/include -I $(SDK)/samples/opencl/SDKUtil/include -o $@ -c $<
     14        g++ -fopenmp -O3 -msse3 -Wfloat-equal -Wall -Wextra -Wpointer-arith -DATI_OS_LINUX -g3 -ffor-scope -I $(SDK)/include -I $(SDK)/samples/opencl/SDKUtil/include -o $@ -c $<
    1515
    1616clean:
Note: See TracChangeset for help on using the changeset viewer.