<commit_before>/*
 * Copyright (c) 2014-2016, imec
 * All rights reserved.
 */

#include <mpi.h>

#include <list>
#include <array>
#include <sstream>
#include <mutex>

const static int CS = 100;
const static int NC  = 5;

template<typename T>
struct SendRecvBuffer
{
    const int peer;
    const int total;

    int num;
    int pos;
    int posted;

    
    std::array<std::vector<T>, NC> data;
    std::array<MPI_Request, NC> req;

    typedef std::list<int> lst;
    lst outstanding, empty, avail;

    int has(const lst &s) const { return !s.empty(); }
    int first(const lst &s) const { return s.front(); }

    int pop(lst &s) { assert(!s.empty()); int i = first(s); s.pop_front(); return i; }
    int push(lst &s, int v) { s.push_back(v); return v;}

    int mark_post()   { return push(outstanding, pop(empty)); } 
    int mark_arrive() { return push(avail, pop(outstanding)); } 
    int mark_sent()   { return push(empty, pop(outstanding)); } 
    int mark_free()   { return push(empty, pop(avail)); } 

    SendRecvBuffer(int p, int t) : peer(p), total(t), num(0), pos(0), posted(0)
    {
        for(int i=0; i<NC; ++i) {
            data[i].resize(CS);
            empty.push_back(i);
        }
    }

    virtual ~SendRecvBuffer() {
        assert(num == total);
    }

    bool has_data() {
        test();
        return has(avail) && !done();
    }

    bool done() { return num == total; }

    virtual void wait() = 0;<commit_msg>Optimize Send/RecvBuffer::has_data<commit_after>/*
 * Copyright (c) 2014-2016, imec
 * All rights reserved.
 */

#include <mpi.h>

#include <list>
#include <array>
#include <sstream>
#include <mutex>

const static int CS = 100;
const static int NC  = 5;

template<typename T>
struct SendRecvBuffer
{
    const int peer;
    const int total;

    int num;
    int pos;
    int posted;

    
    std::array<std::vector<T>, NC> data;
    std::array<MPI_Request, NC> req;

    typedef std::list<int> lst;
    lst outstanding, empty, avail;

    int has(const lst &s) const { return !s.empty(); }
    int first(const lst &s) const { return s.front(); }

    int pop(lst &s) { assert(!s.empty()); int i = first(s); s.pop_front(); return i; }
    int push(lst &s, int v) { s.push_back(v); return v;}

    int mark_post()   { return push(outstanding, pop(empty)); } 
    int mark_arrive() { return push(avail, pop(outstanding)); } 
    int mark_sent()   { return push(empty, pop(outstanding)); } 
    int mark_free()   { return push(empty, pop(avail)); } 

    SendRecvBuffer(int p, int t) : peer(p), total(t), num(0), pos(0), posted(0)
    {
        for(int i=0; i<NC; ++i) {
            data[i].resize(CS);
            empty.push_back(i);
        }
    }

    virtual ~SendRecvBuffer() {
        assert(num == total);
    }

    bool has_data() {
        if (done()) return false;
        if (has(avail)) return true;
        test();
        return has(avail);
    }

    bool done() { return num == total; }

    virtual void wait() = 0;
{'fraction_non_alphanumeric': 0.15890043580288302, 'fraction_numerical': 0.011397921555481059, 'mean_word_length': 2.6794081381011097, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7445564', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1034, 'n_words': 293}