コード例 #1
0
ファイル: sender.cpp プロジェクト: NikitaKarnauhov/lansink
std::function<void(void)> Sender::Impl::_make_worker() {
    return [&]() {
        if (!m_nSockWorker)
            return;

        m_pPlug->log.info("Starting sender thread");
        m_bStarted = true;

        Status prev = m_status;
        const int nSendThresholdFrames = (m_pPlug->nMTU - 100)/get_bytes_per_frame();

        while (m_status & Sender::usRunning) {
            {
                std::lock_guard<std::mutex> lock(m_mutex);

                try {
                    if (prev == Sender::usRunning &&
                            (m_status == Sender::usPaused || m_status == Sender::usUnderrun))
                        _send_pause();
                    else if ((prev == Sender::usPaused || prev == Sender::usUnderrun)
                            && m_status == Sender::usRunning)
                        _send_start();

                    if (!m_queue.empty()) {
                        while (!m_queue.empty() && (
                                m_status != Sender::usRunning ||
                                m_nFramesQueued >= nSendThresholdFrames))
                            _send_data();
                    } else if (m_bPrepared && m_status == Sender::usStopping && _estimate_frames() >= m_nPointer) {
                        _send_stop();
                        m_status = Sender::usStopped;
                        continue;
                    }

                    if (_get_delay() < (snd_pcm_sframes_t)m_pPlug->get_buffer_size()) {
                        // Don't wake up the other party unless there is buffer space available.
                        char buf[1] = {0};
                        write(m_nSockWorker, buf, 1);
                    } else if (m_status == Sender::usUnderrun) {
                        // Resume if buffer filled up after underrun.
                        m_pPlug->log.info("Resuming after XRUN");
                        m_status = Sender::usRunning;
                        m_startTime = Clock::now();
                    }
                } catch (std::exception &e) {
                    m_pPlug->log.error(e.what());
                }

                prev = m_status;
            }

            std::this_thread::sleep_for(std::chrono::milliseconds(m_pPlug->nSendPeriod));
        }
    };
}
コード例 #2
0
ファイル: blu_parallel.c プロジェクト: jys673/Synergy
int main(int argc, char **argv[])
{
 
/* <reference> */
 
    float inSubMat[M][M], outSubMat[M][M], LU[M][M], L[M][M], U[M][M];
    int subdist, rowdist, coldist;
    int i, j, dist, k1, k2, p1, p2, q1, q2, q3;
 
/* </reference> */
 

    double t0, t1;

    t0 = wall_clock();

    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        {
            if (i == j)
            {
                outMat[i][j] = N;
            }
            else
            {
                outMat[i][j] = 1;
            }
        }
    }

     
/* <master id="234567"> */
_distributor = _open_space("distributor", 0, "234567");
_constructor = _open_space("constructor", 0, "234567");
 

    i = 0;
    while (i < N)
    {
        j = i + M - 1;
        dist = M;
        if (j > N-1) 
        {
            j = N-1;
            dist = N - i;
        }
        /* LU factors for submatrix */
        for (k1 = 0; k1 < dist; k1++)
        {
            for (k2 = 0; k2 < dist; k2++)
            {
                inSubMat[k1][k2] = outMat[i+k1][i+k2];
            }
        }
        LUFactor(inSubMat, outSubMat, dist);
        /* update */
        for (k1 = 0; k1 < dist; k1++)
        {
            for (k2 = 0; k2 < dist; k2++)
            {
                outMat[i+k1][i+k2] = outSubMat[k1][k2];
                LU[k1][k2] = outSubMat[k1][k2];
            }
        }

        /* Solve triangles, LZ and WU */

        for (k1 = j+1; k1 < N; k1 = k1+M)
        {
            k2 = k1 + M - 1;
            subdist = M;
            if (k2 > N-1)
            {
                k2 = N - 1;
                subdist = N - k1;
            }
            /* Solve LZ */
            for (p1 = i; p1 < i+M; p1++)
            {
                for (p2 = k1; p2 <= k2; p2++)
                {
                    inSubMat[p1-i][p2-k1] = outMat[p1][p2];
                }
            }
            TriangleSolver(LU, inSubMat, outSubMat, subdist, 1);
            /* update */
            for (p1 = i; p1 < i+M; p1++)
            {
                for (p2 = k1; p2 <= k2; p2++)
                {
                    outMat[p1][p2] = outSubMat[p1-i][p2-k1]; 
                }
            }
            /* Solve WU */
            for (p1 = i; p1 < i+M; p1++)
            {
                for (p2 = k1; p2 <= k2; p2++)
                {
                    inSubMat[p2-k1][p1-i] = outMat[p2][p1];
                }
            }
            TriangleSolver(LU, inSubMat, outSubMat, subdist, 2);
            /* update */
            for (p1 = i; p1 < i+M; p1++)
            {
                for (p2 = k1; p2 <= k2; p2++)
                {
                    outMat[p2][p1] = outSubMat[p2-k1][p1-i]; 
                }
            }
        }

             
_cleanup_space(_distributor, "234567");
_cleanup_space(_constructor, "234567");
    /* <token action="SET" idxset="(k1)"/> */
    sprintf(_tp_name, "token#%s", "234567");
    sprintf(_tp_token, "=(k1:%d~%d,%d:#%d)", j+1, N, 1, M);
    _tp_size = sizeof(_tp_token);
    _tokens  = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size);
    if (_tokens < 0) exit(-1);


    /* <send var="i" type="int"/> */
    sprintf(_tp_name, "int:i#%s", "234567");
    _tp_size = sizeof(int);
    _tp_i_234567 = &i;
    _status  = _send_data(_distributor, _tp_name, (char *)_tp_i_234567, _tp_size);
    if (_status < 0) exit(-1);

 
             
    /* <send var="j" type="int"/> */
    sprintf(_tp_name, "int:j#%s", "234567");
    _tp_size = sizeof(int);
    _tp_j_234567 = &j;
    _status  = _send_data(_distributor, _tp_name, (char *)_tp_j_234567, _tp_size);
    if (_status < 0) exit(-1);

 
             
    /* <send var="outMat" type="float[N(i~N)][N(i~N)]"/> */
    sprintf(_tp_name, "float(%d)(%d):outMat#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "234567", (i), (N), 1, (i), (N), 1, sizeof(float));
    _tp_size = (((N) - (i)) * ((N) - (i))) * sizeof(float);
    _tp_outMat_234567 = (float *)malloc(_tp_size);
    for (_x0_234567 = (i), _y0_234567 =0; _x0_234567 < (N); _x0_234567 +=1, _y0_234567 ++) {
        for (_x1_234567 = (i), _y1_234567 =0; _x1_234567 < (N); _x1_234567 +=1, _y1_234567 ++) {

            _tp_outMat_234567[_y0_234567 * ((N) - (i)) + _y1_234567] = outMat[_x0_234567][_x1_234567];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_outMat_234567, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_outMat_234567);

 

          

             
    /* <read var="outMat" type="float[N(j+1~N)][N(j+1~N)]"/> */
    sprintf(_tp_name, "float(%d)(%d):outMat#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "234567", (j+1), (N), 1, (j+1), (N), 1, sizeof(float));
    _tp_size = (((N) - (j+1)) * ((N) - (j+1))) * sizeof(float);
    _tp_outMat_234567 = (float *)malloc(_tp_size);
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_outMat_234567, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_234567 = (j+1), _y0_234567 =0; _x0_234567 < (N); _x0_234567 +=1, _y0_234567 ++) {
        for (_x1_234567 = (j+1), _y1_234567 =0; _x1_234567 < (N); _x1_234567 +=1, _y1_234567 ++) {

            outMat[_x0_234567][_x1_234567] = _tp_outMat_234567[_y0_234567 * ((N) - (j+1)) + _y1_234567];
        }
    }

    free(_tp_outMat_234567);

 

        i = i + M;
    }

     
_close_space(_constructor, "234567", 1);
_close_space(_distributor, "234567", 1);
/* </master> */
 

/*
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        {
            printf("%6.3f ", outMat[i][j]);
        }
        printf("\n");
    }
*/
    t1 = wall_clock() - t0;
    if (t1>0) printf(" (%f) MFLOPS.\n", (float) 2*N*N*N/3/t1);
    else printf(" MFLOPS: Not measured.\n");
    printf("elapse time = %10.6f\n", t1/1000000);

    return 0;
}
コード例 #3
0
ファイル: matrix_parallel.c プロジェクト: jys673/Synergy
main(int argc, char **argv[])
{
 
/* <reference id="123456"> */
 
    int scalar = 0;
    double A[N][N], B[N][N], C[N][N];
    int i, j, k;
 
/* </reference> */
 

    for (i = 0; i < N ; i++)
    {
        for (j = 0; j < N; j++)
        {
            A[i][j] = (double) i * j ;
            B[i][j] = (double) i * j ;
            C[i][j] = 0;
        }
    }

     
/* <master id="123456"> */
_distributor = _open_space("distributor", 0, "123456");
_constructor = _open_space("constructor", 0, "123456");
 
         
_cleanup_space(_distributor, "123456");
_cleanup_space(_constructor, "123456");
    /* <send var="scalar" type="int" opt="ONCE|XCHG"/> */
    sprintf(_tp_name, "int:scalar#%s", "123456");
    _tp_size = sizeof(int);
    _tp_scalar_123456 = &scalar;
    _status  = _send_data(_constructor, _tp_name, (char *)_tp_scalar_123456, _tp_size);
    if (_status < 0) exit(-1);

 
         
    /* <send var="scalar" type="int" opt="ONCE"/> */
    sprintf(_tp_name, "int:scalar#%s", "123456");
    _tp_size = sizeof(int);
    _tp_scalar_123456 = &scalar;
    _status  = _send_data(_distributor, _tp_name, (char *)_tp_scalar_123456, _tp_size);
    if (_status < 0) exit(-1);

 

         
    /* <send var="A" type="double[N        ][N        ]" opt="ONCE|XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123456");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_A_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            _tp_A_123456[_x0_123456 * (N) + _x1_123456] = A[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_constructor, _tp_name, (char *)_tp_A_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_123456);

 
         
    /* <send var="A" type="double[N(i:i-1) ][N        ]" opt="ONCE|XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", (_i_start-1), (_i_stop-1), _i_step, 0, (N), 1, sizeof(double));
    _tp_size = ((((_i_stop-1) - (_i_start-1) - 1) / _i_step + 1) * (N)) * sizeof(double);
    _tp_A_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = (_i_start-1), _y0_123456 =0; _x0_123456 < (_i_stop-1); _x0_123456 +=_i_step, _y0_123456 ++) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            _tp_A_123456[_y0_123456 * (N) + _x1_123456] = A[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_constructor, _tp_name, (char *)_tp_A_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_123456);

 
         
    /* <send var="A" type="double[N        ][N(k)     ]" opt="ONCE"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", 0, (N), 1, _k_start, _k_stop, _k_step, sizeof(double));
    _tp_size = ((N) * ((_k_stop - _k_start - 1) / _k_step + 1)) * sizeof(double);
    _tp_A_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = _k_start, _y1_123456 =0; _x1_123456 < _k_stop; _x1_123456 +=_k_step, _y1_123456 ++) {

            _tp_A_123456[_x0_123456 * ((_k_stop - _k_start - 1) / _k_step + 1) + _y1_123456] = A[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_A_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_123456);

 
         
    /* <send var="A" type="double[N(i)     ][N(k:$H-1)]" opt="ONCE"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", _i_start, _i_stop, _i_step, _k_stop, (_k_stop-1), _k_step, sizeof(double));
    _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * (((_k_stop-1) - _k_stop - 1) / _k_step + 1)) * sizeof(double);
    _tp_A_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = _i_start, _y0_123456 =0; _x0_123456 < _i_stop; _x0_123456 +=_i_step, _y0_123456 ++) {
        for (_x1_123456 = _k_stop, _y1_123456 =0; _x1_123456 < (_k_stop-1); _x1_123456 +=_k_step, _y1_123456 ++) {

            _tp_A_123456[_y0_123456 * (((_k_stop-1) - _k_stop - 1) / _k_step + 1) + _y1_123456] = A[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_A_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_123456);

 

         
    /* <token action="SET" idxset="(i)(k)"/> */
    sprintf(_tp_name, "token#%s", "123456");
    sprintf(_tp_token, "=(i:%d~%d,%d:#%d)(k:%d~%d,%d:^%d)", 0, N, 1, 100, 0, N, 1, 20);
    _tp_size = sizeof(_tp_token);
    _tokens  = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size);
    if (_tokens < 0) exit(-1);


    /* <send var="scalar" type="int" opt="XCHG"/> */
    sprintf(_tp_name, "int:scalar#%s", "123456");
    _tp_size = sizeof(int);
    _tp_scalar_123456 = &scalar;
    _status  = _send_data(_constructor, _tp_name, (char *)_tp_scalar_123456, _tp_size);
    if (_status < 0) exit(-1);

 
         
    /* <send var="scalar" type="int"/> */
    sprintf(_tp_name, "int:scalar#%s", "123456");
    _tp_size = sizeof(int);
    _tp_scalar_123456 = &scalar;
    _status  = _send_data(_distributor, _tp_name, (char *)_tp_scalar_123456, _tp_size);
    if (_status < 0) exit(-1);

 

         
    /* <send var="B" type="double[N        ][N        ]"/> */
    sprintf(_tp_name, "double(%d)(%d):B#%s", (N), (N), "123456");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_B_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            _tp_B_123456[_x0_123456 * (N) + _x1_123456] = B[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_B_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_B_123456);

 
         
    /* <send var="B" type="double[N(i)     ][N        ]"/> */
    sprintf(_tp_name, "double(%d)(%d):B#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", _i_start, _i_stop, _i_step, 0, (N), 1, sizeof(double));
    _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * (N)) * sizeof(double);
    _tp_B_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = _i_start, _y0_123456 =0; _x0_123456 < _i_stop; _x0_123456 +=_i_step, _y0_123456 ++) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            _tp_B_123456[_y0_123456 * (N) + _x1_123456] = B[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_B_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_B_123456);

 
         
    /* <send var="B" type="double[N        ][N(k:k-1) ]" opt="XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):B#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", 0, (N), 1, (_k_start-1), (_k_stop-1), _k_step, sizeof(double));
    _tp_size = ((N) * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1)) * sizeof(double);
    _tp_B_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = (_k_start-1), _y1_123456 =0; _x1_123456 < (_k_stop-1); _x1_123456 +=_k_step, _y1_123456 ++) {

            _tp_B_123456[_x0_123456 * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1) + _y1_123456] = B[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_constructor, _tp_name, (char *)_tp_B_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_B_123456);

 
         
    /* <send var="B" type="double[N(i:$L-1)][N(k)     ]" opt="XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):B#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", (_i_start-1), _i_start, _i_step, _k_start, _k_stop, _k_step, sizeof(double));
    _tp_size = (((_i_start - (_i_start-1) - 1) / _i_step + 1) * ((_k_stop - _k_start - 1) / _k_step + 1)) * sizeof(double);
    _tp_B_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = (_i_start-1), _y0_123456 =0; _x0_123456 < _i_start; _x0_123456 +=_i_step, _y0_123456 ++) {
        for (_x1_123456 = _k_start, _y1_123456 =0; _x1_123456 < _k_stop; _x1_123456 +=_k_step, _y1_123456 ++) {

            _tp_B_123456[_y0_123456 * ((_k_stop - _k_start - 1) / _k_step + 1) + _y1_123456] = B[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_constructor, _tp_name, (char *)_tp_B_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_B_123456);

 

      

         
    /* <read var="C" type="double[N        ][N        ]"/> */
    sprintf(_tp_name, "double(%d)(%d):C#%s", (N), (N), "123456");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_C_123456 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_C_123456, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            C[_x0_123456][_x1_123456] = _tp_C_123456[_x0_123456 * (N) + _x1_123456];
        }
    }

    free(_tp_C_123456);

 
         
    /* <read var="C" type="double[N(i:i-1) ][N        ]" opt="XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):C#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", (_i_start-1), (_i_stop-1), _i_step, 0, (N), 1, sizeof(double));
    _tp_size = ((((_i_stop-1) - (_i_start-1) - 1) / _i_step + 1) * (N)) * sizeof(double);
    _tp_C_123456 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_C_123456, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_123456 = (_i_start-1), _y0_123456 =0; _x0_123456 < (_i_stop-1); _x0_123456 +=_i_step, _y0_123456 ++) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            C[_x0_123456][_x1_123456] = _tp_C_123456[_y0_123456 * (N) + _x1_123456];
        }
    }

    free(_tp_C_123456);

 
         
    /* <read var="C" type="double[N        ][N(k:k-1) ]" opt="XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):C#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", 0, (N), 1, (_k_start-1), (_k_stop-1), _k_step, sizeof(double));
    _tp_size = ((N) * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1)) * sizeof(double);
    _tp_C_123456 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_C_123456, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = (_k_start-1), _y1_123456 =0; _x1_123456 < (_k_stop-1); _x1_123456 +=_k_step, _y1_123456 ++) {

            C[_x0_123456][_x1_123456] = _tp_C_123456[_x0_123456 * (((_k_stop-1) - (_k_start-1) - 1) / _k_step + 1) + _y1_123456];
        }
    }

    free(_tp_C_123456);

 
         
    /* <read var="C" type="double[N(i:$H-1)][N(k:$L-1)]"/> */
    sprintf(_tp_name, "double(%d)(%d):C#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123456", _i_stop, (_i_stop-1), _i_step, (_k_start-1), _k_start, _k_step, sizeof(double));
    _tp_size = ((((_i_stop-1) - _i_stop - 1) / _i_step + 1) * ((_k_start - (_k_start-1) - 1) / _k_step + 1)) * sizeof(double);
    _tp_C_123456 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_C_123456, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_123456 = _i_stop, _y0_123456 =0; _x0_123456 < (_i_stop-1); _x0_123456 +=_i_step, _y0_123456 ++) {
        for (_x1_123456 = (_k_start-1), _y1_123456 =0; _x1_123456 < _k_start; _x1_123456 +=_k_step, _y1_123456 ++) {

            C[_x0_123456][_x1_123456] = _tp_C_123456[_y0_123456 * ((_k_start - (_k_start-1) - 1) / _k_step + 1) + _y1_123456];
        }
    }

    free(_tp_C_123456);

 

         
    /* <read var="scalar" type="int" opt="_MAX|XCHG"/> */
    sprintf(_tp_name, "int:scalar#%s?MAX@%d", "123456", _tokens);
    _tp_size = sizeof(int);
    _tp_scalar_123456 = &scalar;
    _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_scalar_123456, _tp_size);
    if (_tp_size < 0) exit(-1);

 
         
    /* <read var="scalar" type="int" opt="_MIN"/> */
    sprintf(_tp_name, "int:scalar#%s?MIN@%d", "123456", _tokens);
    _tp_size = sizeof(int);
    _tp_scalar_123456 = &scalar;
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_scalar_123456, _tp_size);
    if (_tp_size < 0) exit(-1);

 

     
_close_space(_constructor, "123456", 1);
_close_space(_distributor, "123456", 1);
/* </master> */
 

    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        {
            printf("%8.1f ", C[i][j]);
        }
        printf("\n");
    }

    exit(0);
}
コード例 #4
0
main(int argc, char **argv[])
{
 
/* <reference id="123456"> */
 
    int i, j, k;
 
/* </reference> */
 

    for (i = 0; i < N ; i++)
    {
        for (j = 0; j < N; j++)
        {
            A[i][j] = (double) i * j ;
            B[i][j] = (double) i * j ;
            C[i][j] = 0;
        }
    }

     
/* <master id="123456"> */
_distributor = _open_space("distributor", 0, "123456");
_constructor = _open_space("constructor", 0, "123456");
 
         
_cleanup_space(_distributor, "123456");
_cleanup_space(_constructor, "123456");
    /* <send var="B" type="double[N   ][N   ]" opt="ONCE"/> */
    sprintf(_tp_name, "double(%d)(%d):B#%s", (N), (N), "123456");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_B_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            _tp_B_123456[_x0_123456 * (N) + _x1_123456] = B[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_B_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_B_123456);

 
         
    /* <token action="SET" idxset="(i)"/> */
    sprintf(_tp_name, "token#%s", "123456");
    sprintf(_tp_token, "=(i:%d~%d,%d:#%d)", 0, N, 1, G);
    _tp_size = sizeof(_tp_token);
    _tokens  = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size);
    if (_tokens < 0) exit(-1);


    /* <send var="A" type="double[N   ][N   ]"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123456");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_A_123456 = (double *)malloc(_tp_size);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            _tp_A_123456[_x0_123456 * (N) + _x1_123456] = A[_x0_123456][_x1_123456];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_A_123456, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_123456);



          

         
    /* <read var="C" type="double[N   ][N   ]"/> */
    sprintf(_tp_name, "double(%d)(%d):C#%s", (N), (N), "123456");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_C_123456 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_C_123456, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_123456 = 0; _x0_123456 < (N); _x0_123456 +=1) {
        for (_x1_123456 = 0; _x1_123456 < (N); _x1_123456 +=1) {

            C[_x0_123456][_x1_123456] = _tp_C_123456[_x0_123456 * (N) + _x1_123456];
        }
    }

    free(_tp_C_123456);

 
     
_close_space(_constructor, "123456", 1);
_close_space(_distributor, "123456", 1);
/* </master> */
 

    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        {
            printf("%8.1f ", C[i][j]);
        }
        printf("\n");
    }

    exit(0);
}
コード例 #5
0
ファイル: init2_parallel.c プロジェクト: jys673/Synergy
int main()
{
     
/* <reference> */
 
    double A[N][N];
    double v;
    int i, j;
     
/* </reference> */
 

    v = 99.9;

     
/* <master id="123"> */
_distributor = _open_space("distributor", 0, "123");
_constructor = _open_space("constructor", 0, "123");
 
     
_cleanup_space(_distributor, "123");
_cleanup_space(_constructor, "123");
    /* <send var="v" type="double" opt="ONCE"/> */
    sprintf(_tp_name, "double:v#%s", "123");
    _tp_size = sizeof(double);
    _tp_v_123 = &v;
    _status  = _send_data(_distributor, _tp_name, (char *)_tp_v_123, _tp_size);
    if (_status < 0) exit(-1);

 
     
    /* <token action="SET" idxset="(j)"/> */
    sprintf(_tp_name, "token#%s", "123");
    sprintf(_tp_token, "=(j:%d~%d,%d:#%d)", 0, N, 1, G);
    _tp_size = sizeof(_tp_token);
    _tokens  = _set_token(_distributor, _tp_name, (char *)_tp_token, _tp_size);
    if (_tokens < 0) exit(-1);


    /* <send var="A" type="double[N][N(j)]"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_A_123 = (double *)malloc(_tp_size);
    for (_x0_123 = 0; _x0_123 < (N); _x0_123 +=1) {
        for (_x1_123 = 0; _x1_123 < (N); _x1_123 +=1) {

            _tp_A_123[_x0_123 * (N) + _x1_123] = A[_x0_123][_x1_123];
        }
    }

    _status  = _send_data(_distributor, _tp_name, (char *)_tp_A_123, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_123);

 

      

     
    /* <read var="A" type="double[N][N(j)]"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s", (N), (N), "123");
    _tp_size = ((N) * (N)) * sizeof(double);
    _tp_A_123 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_A_123, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_123 = 0; _x0_123 < (N); _x0_123 +=1) {
        for (_x1_123 = 0; _x1_123 < (N); _x1_123 +=1) {

            A[_x0_123][_x1_123] = _tp_A_123[_x0_123 * (N) + _x1_123];
        }
    }

    free(_tp_A_123);

 
     
_close_space(_constructor, "123", 1);
_close_space(_distributor, "123", 1);
/* </master> */
 
}
コード例 #6
0
ファイル: lap_234567_11122003.c プロジェクト: jys673/Synergy
main(int argc, char **argv[])
{

/* <worker id="234567"> */
_distributor = _open_space("distributor", 0, "234567");
_constructor = _open_space("constructor", 0, "234567");
 

         
while (1)
{

    /* <token action="GET" idxset="(i)(j)"/> */
    sprintf(_tp_name, "token#%s", "234567");
    _tp_size = 0;
    _tp_size = _get_token(_distributor, _tp_name, (char *)_tp_token, _tp_size);
    if (_tp_size < 0) exit(-1);
    if (_tp_token[0] == '!') break;
    sscanf(_tp_token, "%d@(i:%d~%d,%d)(j:%d~%d,%d)", &_tokens, &_i_start, &_i_stop, &_i_step, &_j_start, &_j_stop, &_j_step);

    if (_tokens >= _batch_flag)
    {
    /* <read var="A" type="double[DIM+2     ][DIM+2     ]"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s", (DIM+2), (DIM+2), "234567");
    _tp_size = ((DIM+2) * (DIM+2)) * sizeof(double);
    _tp_A_234567 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_A_234567, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_234567 = 0; _x0_234567 < (DIM+2); _x0_234567 +=1) {
        for (_x1_234567 = 0; _x1_234567 < (DIM+2); _x1_234567 +=1) {

            A[_x0_234567][_x1_234567] = _tp_A_234567[_x0_234567 * (DIM+2) + _x1_234567];
        }
    }

    free(_tp_A_234567);
    }
    _batch_flag = _tokens;

         
    /* <read var="A" type="double[DIM+2(i:$L-1)][DIM+2(j)     ]" opt="XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (DIM+2), (DIM+2), "234567", (_i_start-1), _i_start, _i_step, _j_start, _j_stop, _j_step, sizeof(double));
    _tp_size = (((_i_start - (_i_start-1) - 1) / _i_step + 1) * ((_j_stop - _j_start - 1) / _j_step + 1)) * sizeof(double);
    _tp_A_234567 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_A_234567, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_234567 = (_i_start-1), _y0_234567 =0; _x0_234567 < _i_start; _x0_234567 +=_i_step, _y0_234567 ++) {
        for (_x1_234567 = _j_start, _y1_234567 =0; _x1_234567 < _j_stop; _x1_234567 +=_j_step, _y1_234567 ++) {

            A[_x0_234567][_x1_234567] = _tp_A_234567[_y0_234567 * ((_j_stop - _j_start - 1) / _j_step + 1) + _y1_234567];
        }
    }

    free(_tp_A_234567);

 
         
    /* <read var="A" type="double[DIM+2(i)     ][DIM+2(j:$L-1)]" opt="XCHG"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (DIM+2), (DIM+2), "234567", _i_start, _i_stop, _i_step, (_j_start-1), _j_start, _j_step, sizeof(double));
    _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * ((_j_start - (_j_start-1) - 1) / _j_step + 1)) * sizeof(double);
    _tp_A_234567 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_constructor, _tp_name, (char *)_tp_A_234567, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_234567 = _i_start, _y0_234567 =0; _x0_234567 < _i_stop; _x0_234567 +=_i_step, _y0_234567 ++) {
        for (_x1_234567 = (_j_start-1), _y1_234567 =0; _x1_234567 < _j_start; _x1_234567 +=_j_step, _y1_234567 ++) {

            A[_x0_234567][_x1_234567] = _tp_A_234567[_y0_234567 * ((_j_start - (_j_start-1) - 1) / _j_step + 1) + _y1_234567];
        }
    }

    free(_tp_A_234567);

 

        /* 
         *  Refine the values in A, these two loops consume most of
         *  the computational time.  
         */

        resid = 0.0;

         
/* <target index ="i" order ="1" limits="(1,rdim+1,1)" chunk ="GRAIN"> */
for (i = _i_start; i < _i_stop; i +=_i_step) 
/* </target> */
 
         {
             
/* <target index ="j" order ="1" limits="(1,DIM+1,1)" chunk ="GRAIN"> */
for (j = _j_start; j < _j_stop; j +=_j_step) 
/* </target> */
 
             {
                Atmp     = A[i][j];
                A[i][j]  = 0.25 * (A[i+1][j] + A[i-1][j] + 
                                   A[i][j+1] + A[i][j-1]);

                residtmp = (Atmp!=0.0? fabs(fabs(A[i][j]-Atmp)/Atmp) : (1.0+EPS));

                if (residtmp > resid)
                    resid = residtmp;
             }
         }

         
    /* <send var="resid" type="double" opt="_MAX"/> */
    sprintf(_tp_name, "double:resid#%s?MAX@%d", "234567", _tokens);
    _tp_size = sizeof(double);
    _tp_resid_234567 = &resid;
    _status  = _send_data(_constructor, _tp_name, (char *)_tp_resid_234567, _tp_size);
    if (_status < 0) exit(-1);

 
         
    /* <send var="A" type="double[DIM+2(i)  ][DIM+2(j)  ]"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (DIM+2), (DIM+2), "234567", _i_start, _i_stop, _i_step, _j_start, _j_stop, _j_step, sizeof(double));
    _tp_size = (((_i_stop - _i_start - 1) / _i_step + 1) * ((_j_stop - _j_start - 1) / _j_step + 1)) * sizeof(double);
    _tp_A_234567 = (double *)malloc(_tp_size);
    for (_x0_234567 = _i_start, _y0_234567 =0; _x0_234567 < _i_stop; _x0_234567 +=_i_step, _y0_234567 ++) {
        for (_x1_234567 = _j_start, _y1_234567 =0; _x1_234567 < _j_stop; _x1_234567 +=_j_step, _y1_234567 ++) {

            _tp_A_234567[_y0_234567 * ((_j_stop - _j_start - 1) / _j_step + 1) + _y1_234567] = A[_x0_234567][_x1_234567];
        }
    }

    _status  = _send_data(_constructor, _tp_name, (char *)_tp_A_234567, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_234567);

 

         
}

_close_space(_constructor, "234567", 0);
_close_space(_distributor, "234567", 0);
/* </worker> */

exit(0);
}
コード例 #7
0
ファイル: tx_state_machine.c プロジェクト: A-Paul/RIOT
/* Returns whether rescheduling is needed or not */
static bool _lwmac_tx_update(gnrc_netif_t *netif)
{
    assert(netif != NULL);

    bool reschedule = false;

    switch (netif->mac.tx.state) {
        case GNRC_LWMAC_TX_STATE_INIT: {
            gnrc_lwmac_clear_timeout(netif, GNRC_LWMAC_TIMEOUT_WR);
            gnrc_lwmac_clear_timeout(netif, GNRC_LWMAC_TIMEOUT_NO_RESPONSE);
            gnrc_lwmac_clear_timeout(netif, GNRC_LWMAC_TIMEOUT_NEXT_BROADCAST);
            gnrc_lwmac_clear_timeout(netif, GNRC_LWMAC_TIMEOUT_BROADCAST_END);

            /* if found ongoing transmission,
             * quit this cycle for collision avoidance. */
            if (_gnrc_lwmac_get_netdev_state(netif) == NETOPT_STATE_RX) {
                if (!gnrc_mac_queue_tx_packet(&netif->mac.tx, 0, netif->mac.tx.packet)) {
                    gnrc_pktbuf_release(netif->mac.tx.packet);
                    LOG_WARNING("WARNING: [LWMAC-tx] TX queue full, drop packet\n");
                }
                /* drop pointer so it wont be free'd */
                netif->mac.tx.packet = NULL;
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            /* check if the packet is for broadcast */
            if (gnrc_netif_hdr_get_flag(netif->mac.tx.packet) &
                (GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) {
                /* Set CSMA retries as configured and enable */
                uint8_t csma_retries = GNRC_LWMAC_BROADCAST_CSMA_RETRIES;
                netif->dev->driver->set(netif->dev, NETOPT_CSMA_RETRIES,
                                        &csma_retries, sizeof(csma_retries));
                netif->mac.mac_info |= GNRC_NETIF_MAC_INFO_CSMA_ENABLED;
                netopt_enable_t csma_enable = NETOPT_ENABLE;
                netif->dev->driver->set(netif->dev, NETOPT_CSMA,
                                        &csma_enable, sizeof(csma_enable));

                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_SEND_BROADCAST;
                reschedule = true;
                break;
            }
            else {
                /* Use CSMA for the first WR */
                netif->mac.mac_info |= GNRC_NETIF_MAC_INFO_CSMA_ENABLED;
                netopt_enable_t csma_disable = NETOPT_ENABLE;
                netif->dev->driver->set(netif->dev, NETOPT_CSMA,
                                        &csma_disable, sizeof(csma_disable));
                /* Set a timeout for the maximum transmission procedure */
                gnrc_lwmac_set_timeout(netif, GNRC_LWMAC_TIMEOUT_NO_RESPONSE, GNRC_LWMAC_PREAMBLE_DURATION_US);

                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_SEND_WR;
                reschedule = true;
                break;
            }
        }
        case GNRC_LWMAC_TX_STATE_SEND_BROADCAST: {
            uint8_t tx_info = _send_bcast(netif);

            if (tx_info & GNRC_LWMAC_TX_SUCCESS) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_SUCCESSFUL;
                reschedule = true;
                break;
            }

            if (tx_info & GNRC_LWMAC_TX_FAIL) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            break;
        }
        case GNRC_LWMAC_TX_STATE_SEND_WR: {
            /* In case of no Tx-isr error (e.g., no Tx-isr), goto TX failure. */
            if (gnrc_lwmac_timeout_is_expired(netif, GNRC_LWMAC_TIMEOUT_NO_RESPONSE)) {
                LOG_WARNING("WARNING: [LWMAC-tx] No response from destination, "
                            "probably no TX-ISR\n");
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }
            LOG_DEBUG("[LWMAC-tx] GNRC_LWMAC_TX_STATE_SEND_WR\n");
            uint8_t tx_info = _send_wr(netif);

            if (tx_info & GNRC_LWMAC_TX_FAIL) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            netif->mac.tx.state = GNRC_LWMAC_TX_STATE_WAIT_WR_SENT;
            reschedule = false;
            break;
        }
        case GNRC_LWMAC_TX_STATE_WAIT_WR_SENT: {
            LOG_DEBUG("[LWMAC-tx] GNRC_LWMAC_TX_STATE_WAIT_WR_SENT\n");

            /* In case of no Tx-isr error (e.g., no Tx-isr), goto TX failure. */
            if (gnrc_lwmac_timeout_is_expired(netif, GNRC_LWMAC_TIMEOUT_NO_RESPONSE)) {
                LOG_WARNING("WARNING: [LWMAC-tx] No response from destination\n");
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            if (gnrc_netif_get_tx_feedback(netif) == TX_FEEDBACK_UNDEF) {
                LOG_DEBUG("[LWMAC-tx] WR not yet completely sent\n");
                break;
            }

            /* If found ongoing transmission, goto TX failure, i.e., postpone transmission to
             * next cycle. This is mainly for collision avoidance. */
            if (gnrc_netif_get_tx_feedback(netif) == TX_FEEDBACK_BUSY) {
                if (!gnrc_mac_queue_tx_packet(&netif->mac.tx, 0, netif->mac.tx.packet)) {
                    gnrc_pktbuf_release(netif->mac.tx.packet);
                    LOG_WARNING("WARNING: [LWMAC-tx] TX queue full, drop packet\n");
                }
                /* clear packet point to avoid TX retry */
                netif->mac.tx.packet = NULL;
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            if (netif->mac.tx.wr_sent == 0) {
                /* Only the first WR use CSMA */
                netif->mac.mac_info &= ~GNRC_NETIF_MAC_INFO_CSMA_ENABLED;
                netopt_enable_t csma_disable = NETOPT_DISABLE;
                netif->dev->driver->set(netif->dev, NETOPT_CSMA,
                                        &csma_disable, sizeof(csma_disable));
            }

            netif->mac.tx.wr_sent++;

            /* Set timeout for next WR in case no WA will be received */
            gnrc_lwmac_set_timeout(netif, GNRC_LWMAC_TIMEOUT_WR, GNRC_LWMAC_TIME_BETWEEN_WR_US);

            /* Debug WR timing */
            LOG_DEBUG("[LWMAC-tx] Destination phase was: %" PRIu32 "\n",
                      netif->mac.tx.current_neighbor->phase);
            LOG_DEBUG("[LWMAC-tx] Phase when sent was:   %" PRIu32 "\n",
                      _gnrc_lwmac_ticks_to_phase(netif->mac.tx.timestamp));
            LOG_DEBUG("[LWMAC-tx] Ticks when sent was:   %" PRIu32 "\n",
                      netif->mac.tx.timestamp);
            _gnrc_lwmac_set_netdev_state(netif, NETOPT_STATE_IDLE);
            netif->mac.tx.state = GNRC_LWMAC_TX_STATE_WAIT_FOR_WA;
            reschedule = false;
            break;
        }
        case GNRC_LWMAC_TX_STATE_WAIT_FOR_WA: {
            LOG_DEBUG("[LWMAC-tx] GNRC_LWMAC_TX_STATE_WAIT_FOR_WA\n");

            if (gnrc_lwmac_timeout_is_expired(netif, GNRC_LWMAC_TIMEOUT_NO_RESPONSE)) {
                LOG_WARNING("WARNING: [LWMAC-tx] No response from destination\n");
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            if (gnrc_lwmac_timeout_is_expired(netif, GNRC_LWMAC_TIMEOUT_WR)) {
                /* In case the sender is in consecutive (burst) transmission to the receiver,
                 * meaning that the sender has already successfully sent at least one data to
                 * the receiver, then the sender will only spend one WR for triggering the next
                 * transmission procedure. And, if this WR doesn't work (no WA replied), the
                 * sender regards consecutive transmission failed.
                 */
                if (gnrc_lwmac_get_tx_continue(netif)) {
                    LOG_DEBUG("[LWMAC-tx] Tx burst fail\n");
                    if (!gnrc_mac_queue_tx_packet(&netif->mac.tx, 0, netif->mac.tx.packet)) {
                        gnrc_pktbuf_release(netif->mac.tx.packet);
                        LOG_WARNING("WARNING: [LWMAC-tx] TX queue full, drop packet\n");
                    }
                    /* drop pointer so it wont be free'd */
                    netif->mac.tx.packet = NULL;

                    netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                    reschedule = true;
                    break;
                }
                else {
                    /* If this is the first transmission to the receiver for locating the
                     * latter's wake-up period, the sender just keep sending WRs until it
                     * finds the WA.
                     */
                    netif->mac.tx.state = GNRC_LWMAC_TX_STATE_SEND_WR;
                    reschedule = true;
                    break;
                }
            }

            if (_gnrc_lwmac_get_netdev_state(netif) == NETOPT_STATE_RX) {
                /* Wait for completion of frame reception */
                break;
            }

            uint8_t tx_info = _packet_process_in_wait_for_wa(netif);

            if (tx_info & GNRC_LWMAC_TX_FAIL) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            if (tx_info & GNRC_LWMAC_TX_SUCCESS) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_SEND_DATA;
                reschedule = true;
                break;
            }
            else {
                /* No WA yet */
                break;
            }
        }
        case GNRC_LWMAC_TX_STATE_SEND_DATA: {
            LOG_DEBUG("[LWMAC-tx] GNRC_LWMAC_TX_STATE_SEND_DATA\n");

            if (!_send_data(netif)) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            netif->mac.tx.state = GNRC_LWMAC_TX_STATE_WAIT_FEEDBACK;
            reschedule = false;
            break;
        }
        case GNRC_LWMAC_TX_STATE_WAIT_FEEDBACK: {
            /* In case of no Tx-isr error, goto TX failure. */
            if (gnrc_lwmac_timeout_is_expired(netif, GNRC_LWMAC_TIMEOUT_NO_RESPONSE)) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            LOG_DEBUG("[LWMAC-tx] GNRC_LWMAC_TX_STATE_WAIT_FEEDBACK\n");
            if (gnrc_netif_get_tx_feedback(netif) == TX_FEEDBACK_UNDEF) {
                break;
            }
            else if (gnrc_netif_get_tx_feedback(netif) == TX_FEEDBACK_SUCCESS) {
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_SUCCESSFUL;
                reschedule = true;
                break;
            }
            else if (gnrc_netif_get_tx_feedback(netif) == TX_FEEDBACK_NOACK) {
                LOG_ERROR("ERROR: [LWMAC-tx] Not ACKED\n");
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }
            else if (gnrc_netif_get_tx_feedback(netif) == TX_FEEDBACK_BUSY) {
                LOG_ERROR("ERROR: [LWMAC-tx] Channel busy \n");
                netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
                reschedule = true;
                break;
            }

            LOG_ERROR("ERROR: [LWMAC-tx] Tx feedback unhandled: %i\n",
                      gnrc_netif_get_tx_feedback(netif));
            netif->mac.tx.state = GNRC_LWMAC_TX_STATE_FAILED;
            reschedule = true;
            break;
        }
        case GNRC_LWMAC_TX_STATE_SUCCESSFUL:
        case GNRC_LWMAC_TX_STATE_FAILED: {
            break;
        }
        case GNRC_LWMAC_TX_STATE_STOPPED: {
            LOG_DEBUG("[LWMAC-tx] Transmission state machine is stopped\n");
        }
    }

    return reschedule;
}
コード例 #8
0
ファイル: init3_123.c プロジェクト: jys673/Synergy
main(int argc, char **argv[])
{

/* <worker id="123"> */
_distributor = _open_space("distributor", 0, "123");
_constructor = _open_space("constructor", 0, "123");
 
     
    /* <read var="v" type="double" opt="ONCE"/> */
    sprintf(_tp_name, "double:v#%s", "123");
    _tp_size = sizeof(double);
    _tp_v_123 = &v;
    _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_v_123, _tp_size);
    if (_tp_size < 0) exit(-1);

 
     
while (1)
{

    /* <token action="GET" idxset="(i)(j)"/> */
    sprintf(_tp_name, "token#%s", "123");
    _tp_size = 0;
    _tp_size = _get_token(_distributor, _tp_name, (char *)_tp_token, _tp_size);
    if (_tp_size < 0) exit(-1);
    if (_tp_token[0] == '!') break;
    sscanf(_tp_token, "%d@(i:%d~%d,%d)(j:%d~%d,%d)", &_tokens, &_i_start, &_i_stop, &_i_step, &_j_start, &_j_stop, &_j_step);


    /* <read var="A" type="double[N(i)][N(j)]"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123", _i_start, _i_stop, 1, _j_start, _j_stop, 1, sizeof(double));
    _tp_size = (((_i_stop - _i_start - 1) / 1 + 1) * ((_j_stop - _j_start - 1) / 1 + 1)) * sizeof(double);
    _tp_A_123 = (double *)malloc(_tp_size);
    _tp_size = _read_data(_distributor, _tp_name, (char *)_tp_A_123, _tp_size);
    if (_tp_size < 0) exit(-1);
    for (_x0_123 = _i_start, _y0_123 =0; _x0_123 < _i_stop; _x0_123 +=1, _y0_123 ++) {
        for (_x1_123 = _j_start, _y1_123 =0; _x1_123 < _j_stop; _x1_123 +=1, _y1_123 ++) {

            A[_x0_123][_x1_123] = _tp_A_123[_y0_123 * ((_j_stop - _j_start - 1) / 1 + 1) + _y1_123];
        }
    }

    free(_tp_A_123);

 

     
/* <target index ="i" order ="1" limits="(0,N,1)" chunk ="G"> */
for (i = _i_start; i < _i_stop; i +=_i_step) 
/* </target> */
 
    {
         
/* <target index ="j" order ="2" limits="(0,N,1)" chunk ="G"> */
for (j = _j_start; j < _j_stop; j +=_j_step) 
/* </target> */
 
        {
            A[i, j] = v;
        }
    }

     
    /* <send var="A" type="double[N(i)][N(j)]"/> */
    sprintf(_tp_name, "double(%d)(%d):A#%s[%d~%d,%d][%d~%d,%d]@%d", (N), (N), "123", _i_start, _i_stop, 1, _j_start, _j_stop, 1, sizeof(double));
    _tp_size = (((_i_stop - _i_start - 1) / 1 + 1) * ((_j_stop - _j_start - 1) / 1 + 1)) * sizeof(double);
    _tp_A_123 = (double *)malloc(_tp_size);
    for (_x0_123 = _i_start, _y0_123 =0; _x0_123 < _i_stop; _x0_123 +=1, _y0_123 ++) {
        for (_x1_123 = _j_start, _y1_123 =0; _x1_123 < _j_stop; _x1_123 +=1, _y1_123 ++) {

            _tp_A_123[_y0_123 * ((_j_stop - _j_start - 1) / 1 + 1) + _y1_123] = A[_x0_123][_x1_123];
        }
    }

    _status  = _send_data(_constructor, _tp_name, (char *)_tp_A_123, _tp_size);
    if (_status < 0) exit(-1);
    free(_tp_A_123);

 
     
}

_close_space(_constructor, "123", 0);
_close_space(_distributor, "123", 0);
/* </worker> */

exit(0);
}