jeudi 25 octobre 2018

How to add OpenMP for loop by replacing the while loop of a sequential code

the following code is written sequentially. I want to implement OpenMP by replacing while loop to for loop but have no idea how to do this. I know the OpenMP syntax but unable to implement.

The reason to do parallelism is to check the performance between sequential and parallel technique. Any help?

  void block::mine_block(uint32_t difficulty) noexcept
{
    string str(difficulty, '0');

    auto start = system_clock::now();

    while (_hash.substr(0, difficulty) != str)
    {
        ++_nonce;
        _hash = calculate_hash();
    }

    auto end = system_clock::now();
    duration<double> diff = end - start;

    cout << "Block mined: " << _hash << " in " << diff.count() << " seconds" << endl;
}

Aucun commentaire:

Enregistrer un commentaire