当前位置: 首页>>代码示例>>C++>>正文


C++ hpx::wait_all方法代码示例

本文整理汇总了C++中hpx::wait_all方法的典型用法代码示例。如果您正苦于以下问题:C++ hpx::wait_all方法的具体用法?C++ hpx::wait_all怎么用?C++ hpx::wait_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hpx的用法示例。


在下文中一共展示了hpx::wait_all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LU

void LU( int numBlocks)
{
    printf("LU\n");
    hpx::naming::id_type here = hpx::find_here();
    vector<vector<block> > blockList;
    getBlockList(blockList, numBlocks);
    vector<vector<vector<shared_future<block> > > > dfArray(numBlocks);
    shared_future<block> *diag_block, *first_col;

    for(int i = 0; i < numBlocks; i++){
        dfArray[i].resize(numBlocks);
        for(int j = 0; j < numBlocks; j++){
            dfArray[i][j].resize(numBlocks, hpx::make_ready_future(block()));
        }
    }
    //first iteration through matrix, initialized vector of futures
    dfArray[0][0][0] = async( ProcessDiagonalBlock, blockList[0][0] );
    diag_block = &dfArray[0][0][0];
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][0][i] = dataflow( unwrapped( &ProcessBlockOnRow ),
            hpx::make_ready_future( blockList[0][i] ), *diag_block);
    }
    for(int i = 1; i < numBlocks; i++) {
        dfArray[0][i][0] = dataflow( unwrapped( &ProcessBlockOnColumn ),
            hpx::make_ready_future( blockList[i][0] ), *diag_block);
        first_col = &dfArray[0][i][0];
        for(int j = 1; j < numBlocks; j++) {
            dfArray[0][i][j] = dataflow( unwrapped( &ProcessInnerBlock ),
                hpx::make_ready_future( blockList[i][j]), dfArray[0][0][j], *first_col );
        }
    }
    //all calculation after initialization. Each iteration,
    //the number of tasks/blocks spawned is decreased.
    for(int i = 1; i < numBlocks; i++) {
        dfArray[i][i][i] = dataflow( unwrapped( &ProcessDiagonalBlock ),
            dfArray[i-1][i][i]);
        diag_block = &dfArray[i][i][i];
        for(int j = i + 1; j < numBlocks; j++){
            dfArray[i][i][j] = dataflow( unwrapped(&ProcessBlockOnRow),
                dfArray[i-1][i][j], *diag_block);
        }
        for(int j = i + 1; j < numBlocks; j++){
            dfArray[i][j][i] = dataflow( unwrapped( &ProcessBlockOnColumn ),
                dfArray[i-1][j][i], *diag_block);
            first_col = &dfArray[i][j][i];
            for(int k = i + 1; k < numBlocks; k++) {
                dfArray[i][j][k] = dataflow( unwrapped( &ProcessInnerBlock ),
                    dfArray[i-1][j][k], dfArray[i][i][k], *first_col );
            }
        }
    }
    wait_all(dfArray[numBlocks-1][numBlocks-1][numBlocks-1]);
}
开发者ID:pra85,项目名称:hpx,代码行数:53,代码来源:dataflow_791.cpp

示例2: InitMatrix3

void InitMatrix3()
{
    vector<shared_future<void> > futures;
    futures.reserve(size);
    for(int i = 0; i < size; i++)
        for(int j = 0; j < size; j++){
            if(i >= j)
                L[i*size + j] = i-j+1;
            else
                L[i*size + j] = 0;
            if(i <= j)
                U[i*size + j] = j-i+1;
            else
                U[i*size + j] = 0;
        }
    for(int i = 0; i < size; i++) {
        futures.push_back( async( initLoop, i));
    }
    wait_all(futures);
}
开发者ID:pra85,项目名称:hpx,代码行数:20,代码来源:dataflow_791.cpp

示例3: hpx_main

int hpx_main()
{
    BMP SetImage;
    SetImage.SetBitDepth(24);
    SetImage.SetSize(sizeX * 2,sizeY);
    hpx::util::high_resolution_timer t;

    {
        using namespace std;

        using hpx::future;
        using hpx::async;
        using hpx::wait_all;

        int const max_iteration = 255;

        vector<future<int> > iteration;
        iteration.reserve(sizeX*sizeY);

        hpx::cout << "Initial setup completed in " 
                  << t.elapsed() 
                  << "s. Initializing and running futures...\n";
        t.restart();

        hpx::id_type const here = hpx::find_here();
        fractals_action fractal_pixel;

        for (int i = 0; i < sizeX; i++)
        {
            for (int j = 0; j < sizeY; j++)
            {
                float x0 = (float)i * 3.5f / (float)sizeX - 2.5f;
                float y0 = (float)j * 2.0f / (float)sizeY - 1.0f;

                iteration.push_back(async(fractal_pixel, here, x0, y0, max_iteration));
            }
        }
        wait_all(iteration);

        hpx::cout << sizeX*sizeY << " calculations run in " 
                  << t.elapsed() 
                  << "s. Transferring from futures to general memory...\n";
        t.restart();

        for (int i = 0; i < sizeX; ++i)
        {
            for (int j = 0; j < sizeY; ++j)
            {
                int it = iteration[i*sizeX + j].get();
                for (int k = 0; k < 2; ++k)
                {
                    int p = (it * 255) / max_iteration;
                    SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p));
                }
            }
        }
    }

    hpx::cout << "Transfer process completed in " 
              << t.elapsed() << "s. Writing to hard disk...\n";
    t.restart();

    SetImage.WriteToFile("out.bmp");
    
    hpx::cout << "Fractal image written to file \"out.bmp\" from memory in " 
              << t.elapsed() << "s.\nInitializing shutdown process.\n";

    return hpx::finalize(); // Handles HPX shutdown
}
开发者ID:AntonBikineev,项目名称:hpx,代码行数:69,代码来源:fractals.cpp

示例4: hpx_main

int hpx_main()
{
    
    {
        using namespace std;
        ifstream fin;
        string path = __FILE__;
        string wordlist_path;
        string remove = "spell_check.cpp";
        for (int i = 0; i < path.length() - remove.length(); i++)
        {
            wordlist_path.push_back(path[i]);
            if (path[i] == '\\')
            {
                wordlist_path.push_back(path[i]);
            }
        }
        //list of American English words in alphabetical order. Provided by Kevin at http://wordlist.sourceforge.net/
        wordlist_path = wordlist_path + "5desk.txt";
        fin.open(wordlist_path);
        int wordcount = 0;
        cout << "Reading dictionary file to memory...\n";
        hpx::util::high_resolution_timer t;
        if(fin.is_open())
        {
            string temp;
            while (fin.good())
            {
                getline(fin, temp);
                for (int i = 0; i < temp.length(); i++)
                temp[i] = tolower(temp[i]);
                words.push_back(temp);
                wordcount++;
            }
            cout << wordcount << " words loaded in " << t.elapsed() << "s.\n";
        }
        else
        {
            cout << "Error: Unable to open file.\n";
            return hpx::finalize();
        }
        fin.close();
        char* word = new char[1024];
        cout << "Enter the words you would like to spellcheck, separated by a \"Space\", and then press \"Enter\".\n";
        cin.getline(word,1024, '\n');
        vector<bool> contraction;
        vector<string> strs;
        {
            vector<string> temp;
            boost::split(temp, word, boost::is_any_of("\n\t -"));
            for (int i = 0; i < temp.size(); i++)
            {
                bool isContraction = false;
                string holder;
                for (int j = 0; j < temp[i].size(); j++)
                {
                    //a size check to avoid errors
                    if (temp[i].size() - j - 1 == 2)
                    {
                    //if this is a contraction, ignore the rest of it...
                        if (temp[i][j+1] == '\'' && temp[i][j] == 'n' && temp[i][j+2] == 't')
                        {
                            //but label this as a contraction
                            isContraction = true;
                            break;
                        }
                    }
                    //remove any garbage characters
                    if (toupper(temp[i][j]) >= 'A' && toupper(temp[i][j]) <= 'Z')
                        holder.push_back(tolower(temp[i][j]));
                }
                if (holder.size() > 0)
                {
                    contraction.push_back(isContraction);
                    strs.push_back(holder);
                }
            }
        }
        t.restart();
        {
            using hpx::lcos::future;
            using hpx::async;
            using hpx::wait_all;
            vector<search_action> sAct;//[sizeX * sizeY];
            vector<future<string>> wordRun;
            wordRun.reserve(strs.size());
            for (int i = 0; i < strs.size(); ++i)
            {
                string& single = strs[i]; 
                int start = 0;
                hpx::naming::id_type const locality_id = hpx::find_here();
                search_action temp;
                wordRun.push_back(async(temp, locality_id, start, wordcount, single));
                sAct.push_back(temp);
                //cout << search(0, wordcount, single) << endl;
            }
            wait_all(wordRun);
            cout << "Search completed in " << t.elapsed() << "s.\n";
            for (int i = 0; i < strs.size(); i++)
            {
//.........这里部分代码省略.........
开发者ID:sqandr,项目名称:hpx,代码行数:101,代码来源:spell_check.cpp


注:本文中的hpx::wait_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。