Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. void nqueens(char *config, int n, int i)
  2. {
  3. char *new_config;
  4. int j;
  5.  
  6. if (i==n)
  7. {
  8. #pragma omp atomic
  9. count++;
  10. }
  11. for (j=0; j<n; j++)
  12. {
  13. if (i < 1){
  14. new_config = malloc((i+1)*sizeof(char));
  15. memcpy(new_config, config, i*sizeof(char));
  16. #pragma omp task
  17. {
  18. if (safe(new_config, i, j))
  19. {
  20. new_config[i] = j;
  21. nqueens(new_config, n, i+1);
  22. }
  23. }
  24.  
  25. #pragma omp taskwait
  26. free(new_config);
  27. }else{
  28. new_config = malloc((i+1)*sizeof(char));
  29. memcpy(new_config, config, i*sizeof(char));
  30. if (safe(new_config, i, j))
  31. {
  32. new_config[i] = j;
  33. nqueens_serial(new_config, n, i+1);
  34. }
  35. free(new_config);
  36. }
  37. }
  38.  
  39. return;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement