dtaidistance/lib/DTAIDistanceC/DTAIDistanceC/dd_dtw_openmp.c
/*!
Distance matrix for n-dimensional DTW, executed on a list of pointers to arrays and in parallel.

@see dtw_distances_ptrs
*/
Distance matrix for n-dimensional DTW, executed on a list of pointers to arrays and in parallel.
Distance matrix for n - dimensional DTW executed on a list of pointers to arrays and in parallel .
idx_t dtw_distances_ptrs_parallel(seq_t **ptrs, idx_t nb_ptrs, idx_t* lengths, seq_t* output,
                     DTWBlock* block, DTWSettings* settings) {
#if defined(_OPENMP)
    idx_t r, c, r_i, c_i;
    idx_t length;
    idx_t *cbs, *rls;
    if (dtw_distances_prepare(block, nb_ptrs, &cbs, &rls, &length, settings) != 0) {
        return 0;
    }
    r_i=0;
    #pragma omp parallel for private(r_i, c_i, r, c) schedule(guided)
    for (r_i=0; r_i < (block->re - block->rb); r_i++) {
        r = block->rb + r_i;
        c_i = 0;
        for (c=cbs[r_i]; c<block->ce; c++) {
            double value = dtw_distance(ptrs[r], lengths[r],
                                        ptrs[c], lengths[c], settings);
            output[rls[r_i] + c_i] = value;
            c_i++;
        }
    }
    free(cbs);
    free(rls);
    return length;
#else
    printf("ERROR: DTAIDistanceC is compiled without OpenMP support.\n");
    return 0;
#endif
}
idx_t dtw_distances_ptrs_parallel ( seq_t * * ptrs , idx_t nb_ptrs , idx_t * lengths , seq_t * output , DTWBlock * block , DTWSettings * settings ) { #if defined ( _OPENMP ) idx_t r , c , r_i , c_i ; idx_t length ; idx_t * cbs , * rls ; if ( dtw_distances_prepare ( block , nb_ptrs , & cbs , & rls , & length , settings ) != 0 ) { return 0 ; } r_i = 0 ; #pragma  omp parallel for private(r_i, c_i, r, c) schedule(guided) for ( r_i = 0 ; r_i < ( block -> re - block -> rb ) ; r_i ++ ) { r = block -> rb + r_i ; c_i = 0 ; for ( c = cbs [ r_i ] ; c < block -> ce ; c ++ ) { double value = dtw_distance ( ptrs [ r ] , lengths [ r ] , ptrs [ c ] , lengths [ c ] , settings ) ; output [ rls [ r_i ] + c_i ] = value ; c_i ++ ; } } free ( cbs ) ; free ( rls ) ; return length ; #else printf ( " \n " ) ; return 0 ; #endif }
Distance matrix for n-dimensional DTW, executed on a list of pointers to arrays and in parallel.
Distance matrix for n - dimensional DTW executed on a list of pointers to arrays and in parallel .
// Rows have different lengths, thus use guided scheduling to make threads with shorter rows // not wait for threads with longer rows. Also the first rows are always longer than the last // ones (upper triangular matrix), so this nicely aligns with the guided strategy. // Using schedule("static, 1") is also fast for the same reason (neighbor rows are almost // the same length, thus a circular assignment works well) but assumes all DTW computations take // the same amount of time. // printf("r_i=%zu - r=%zu - c_i=%zu - c=%zu\n", r_i, r, c_i, c); //            printf("r_i=%zu - r=%zu - c_i=%zu - c=%zu - value=%.4f\n", r_i, r, c_i, c, value); //            printf("rls[r_i] + c_i = %zu + %zu\n", rls[r_i], c_i);