<commit_before>/*
 * Copyright 2017-2018 <NAME>, <NAME> University Linz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cassert>
#include <cstring>
#include <unistd.h>

#include "fpi.hpp"
#include "uintqueue.hpp"

namespace pg {

FPISolver::FPISolver(Oink *oink, Game *game) : Solver(oink, game)
{
}

FPISolver::~FPISolver()
{
}

TASK_3(int, update_block_rec, FPISolver*, solver, int, i, int, n)
{
    if (n>128) {
        // because dynamic bitset is not thread safe, work in blocks of 64...
        int N = (n/128)*64;
        SPAWN(update_block_rec, solver, i+N, n-N);
        int a = CALL(update_block_rec, solver, i, N);
        int b = SYNC(update_block_rec);
        return a+b;
    } else {
        return solver->updateBlock(i, n);
    }
}

VOID_TASK_4(freeze_thaw_reset_rec, FPISolver*, solver, int, i, int, n, int, p)
{
    if (n>128) {
        // because dynamic bitset is not thread safe, work in blocks of 64...
        int N = (n/128)*64;
        SPAWN(freeze_thaw_reset_rec, solver, i+N, n-N, p);
        CALL(freeze_thaw_reset_rec, solver, i, N, p);
        SYNC(freeze_thaw_reset_rec);
    } else {
        solver->freezeThawReset(i, n, p);
    }
}

int
FPISolver::updateBlock(int i, int n)
{
    int res = 0;
    for (; n != 0; i++, n--) {
        if (disabled[i]) continue;
        if (frozen[i]) continue;
        if (distraction[i]) continue;

        // update whether current vertex <i> is a distraction by computing the one step winner
        int onestep_winner;
        if (owner(i) == 0) {
            // see if player Even can go to a vertex currently good for Even
            onestep_winner = 1;
            for (auto curedge = outs(i); *curedge != -1; curedge++) {
                int to = *curedge;
                if (disabled[to]) continue;
                const int winner_to = parity[to] ^ distraction[to];
                if (winner_to == 0) {
                    // good for player Even
                    onestep_winner = 0;
                    // and set the strategy<commit_msg>Fix a corner case in the parallel version of FPI<commit_after>/*
 * Copyright 2017-2018 <NAME>, <NAME> University Linz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cassert>
#include <cstring>
#include <unistd.h>

#include "fpi.hpp"
#include "uintqueue.hpp"

namespace pg {

FPISolver::FPISolver(Oink *oink, Game *game) : Solver(oink, game)
{
}

FPISolver::~FPISolver()
{
}

TASK_3(int, update_block_rec, FPISolver*, solver, int, i, int, n)
{
    if (n>128) {
        // because dynamic bitset is not thread safe, work in blocks of 64...
        if (i&127) {
            // start not yet aligned
            int N = 128 - (i&127);
            SPAWN(update_block_rec, solver, i+N, n-N);
            int a = solver->updateBlock(i, N);
            int b = SYNC(update_block_rec);
            return a+b;
        } else {
            int N = (n/128)*64;
            SPAWN(update_block_rec, solver, i+N, n-N);
            int a = CALL(update_block_rec, solver, i, N);
            int b = SYNC(update_block_rec);
            return a+b;
        }
    } else {
        return solver->updateBlock(i, n);
    }
}

VOID_TASK_4(freeze_thaw_reset_rec, FPISolver*, solver, int, i, int, n, int, p)
{
    if (n>128) {
        // because dynamic bitset is not thread safe, work in blocks of 64...
        if (i&127) {
            // start not yet aligned
            int N = 128 - (i&127);
            SPAWN(freeze_thaw_reset_rec, solver, i+N, n-N, p);
            solver->freezeThawReset(i, N, p);
            SYNC(freeze_thaw_reset_rec);
        } else {
            int N = (n/128)*64;
            SPAWN(freeze_thaw_reset_rec, solver, i+N, n-N, p);
            CALL(freeze_thaw_reset_rec, solver, i, N, p);
            SYNC(freeze_thaw_reset_rec);
        }
    } else {
        solver->freezeThawReset(i, n, p);
    }
}

int
FPISolver::updateBlock(int i, int n)
{
    int res = 0;
    for (; n != 0; i++, n--) {
        if (disabled[i]) continue;
        if (frozen[i]) continue;
        if (distraction[i]) continue;

        // update whether current vertex <i> is a distraction by computing the one step winner
        int onestep_winner;
        if (owner(i) == 0) {
            // see if player Even can go to a vertex currently good for Even
            onestep_winner = 1;
            for (auto curedge = outs(i); *curedge != -1; curedge++) {
                int to = *curedge;
                if (disabled[to]) continue;
                const int winner_to = parity[to] ^ distraction[to];
                if (winner_to == 0) {
                    // good for player Even
                    onestep_winner = 0;
                    // and set the strategy
{'fraction_non_alphanumeric': 0.1156735977634108, 'fraction_numerical': 0.017473353136466887, 'mean_word_length': 2.1870824053452114, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '855015', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1833, 'n_words': 604}