Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9091749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:41:14+00:00 2026-06-16T22:41:14+00:00

I have asked a similar question before ,but I have not obtained enough attention

  • 0

I have asked a similar question before ,but I have not obtained enough attention to my problem due to the complexity of it , so let me rephrase the whole problem .

moveT ChooseComputerMove(state)
{
 moveT bestMove;
 maxMove(state,bestMove);

 return bestMove;
}

int maxMove(state, bestMove)
{

  int v = -1000;

  #pragma omp parallel for 
  for(int i = 0; i< nMoves; i++)
  {

   moveT move = validMoves[i];

   makemove(state,move);

   #pragma omp task 

   rating = -maxMove(state, move);

    if(rating < v)
      {v=rating ; bestMove = move;}

    #pragma omp taskwait   

    Retractmove(state,move)
 }

 return v;
}

Is my code semantically correct ; I already have tested it in my code , and it gives me segmentation fault;

Update : Sorry for the spelling mistakes and I have edited my code .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:41:15+00:00Added an answer on June 16, 2026 at 10:41 pm

    Consider this a comment. Your explicit task region is incorrectly written and besides that it is also redundant. You spawn only one explicit task in each iteration and then wait for it to finish with the taskwait. But since task execution may be deferred, the task itself might execute after the line with the comparison operator. E.g.

    #pragma omp task
    rating = -maxMove(state, move); // <-- This stmt is the body of the task
    
    if(rating < v)
      {v=rating ; bestMove = move;}
    
    #pragma omp taskwait
    

    The body of the task is the next block that follows the task pragma.

    The actual execution flow might be:

    • The task is created but queued.
    • The if(rating < v) .... statement is executed.
    • The taskwait construct is hit which blocks execution until all tasks are processed. This initiates the execution of the task.
    • The new rating is computed but the value of v is never updated since the if statement was already executed.

    You would rather want to put both statements in a task construct and also remove the taskwait since it is implied at the end of the parallel region. Since makemove modifies the state vector, you might want to employ the single task producer pattern:

    #pragma omp parallel
    {
       #pragma omp single nowait
       for(int i = 0; i < nMoves; i++)
       {
          moveT move = validMoves[i], opponentsBestMove;
    
          makemove(state, move);
    
          #pragma omp task firstprivate(state)
          {
             // Declare rating here
             int rating = -maxMove(state, opponentsBestMove);
    
             #pragma omp critical
             if (rating > v) { v = rating; bestMove = move; }
          }
    
          Retractmove(state, move)
       }
    
       // An implicit taskwait here
    }
    

    The task producer loop is run in serial in one thread only (because of the single directive). Then at the end of the parallel region there is an implicit task scheduling point, hence the other threads start executing the queued tasks. The state is shared by default and has to be made firstprivate in order for the task to inherit a private version, otherwise all tasks would modify the same global state variable at the same time which would lead to problems. The privatisation of state would result in much higher memory usage, hence it is not a good idea to allow tasking up to the bottom of the recursion tree. Rather you should stop generating tasks at a certain level and continue with serial execution. This would also reduce the overhead induced by the explicit tasking.

    Another thing to notice – unless special measures are taken, only the top-level call would run in parallel. All other recursive calls would result in nested parallel regions and nested parallelism is disabled by default, which means that deeper recursion levels would automatically execute serially. To enable nested parallelism, either set the environment value OMP_NESTED to true or put the following call somewhere in the beginning of the program:

    #include <omp.h>
    
    ...
    omp_set_nested(1);
    ...
    // Now call the recursive function
    ...
    

    Beware that this might result in a huge number of concurrent threads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Before I start, yes I have asked a similar question before; unfortunately due to
I have asked a similar question before, but didn't get very good results. I've
I asked a similar question before but the response was pretty weak, so not
I have asked a similar question like this before but I am going to
I've asked a very similar question before, but this time is not about VB
Similar questions have been asked before but this question strives to explore more options
Another Newbie question in XSLT transformation. (I have asked similar question before, but in
I have asked a similar question before, but I didn't have a firm grasp
similar questions have been asked before but I cant find an exact match to
I know similar questions have been asked before, but I've tried many times and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.