Skip to content

Commit 856ab74

Browse files
committed
removed openmp implementation for the simplex algorithm since no real runtime gains observed
1 parent aed0120 commit 856ab74

7 files changed

Lines changed: 15 additions & 1767 deletions

File tree

ot/lp/EMD.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ enum ProblemType {
3030
};
3131

3232
int EMD_wrap(int n1,int n2, double *X, double *Y,double *D, double *G, double* alpha, double* beta, double *cost, uint64_t maxIter, double* alpha_init, double* beta_init);
33-
int EMD_wrap_omp(int n1,int n2, double *X, double *Y,double *D, double *G, double* alpha, double* beta, double *cost, uint64_t maxIter, int numThreads);
34-
3533
int EMD_wrap_sparse(
3634
int n1,
3735
int n2,

ot/lp/EMD_wrapper.cpp

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
#include "network_simplex_simple.h"
17-
#include "network_simplex_simple_omp.h"
1817
#include "sparse_bipartitegraph.h"
1918
#include "EMD.h"
2019
#include <cstdint>
@@ -300,87 +299,6 @@ int EMD_wrap(int n1, int n2, double *X, double *Y, double *D, double *G,
300299

301300

302301

303-
int EMD_wrap_omp(int n1, int n2, double *X, double *Y, double *D, double *G,
304-
double* alpha, double* beta, double *cost, uint64_t maxIter, int numThreads) {
305-
// beware M and C are stored in row major C style!!!
306-
307-
using namespace lemon_omp;
308-
uint64_t n, m, cur;
309-
310-
typedef FullBipartiteDigraph Digraph;
311-
DIGRAPH_TYPEDEFS(Digraph);
312-
313-
// Get the number of non zero coordinates for r and c
314-
n=0;
315-
for (int i=0; i<n1; i++) {
316-
double val=*(X+i);
317-
if (val>0) {
318-
n++;
319-
}else if(val<0){
320-
return INFEASIBLE;
321-
}
322-
}
323-
m=0;
324-
for (int i=0; i<n2; i++) {
325-
double val=*(Y+i);
326-
if (val>0) {
327-
m++;
328-
}else if(val<0){
329-
return INFEASIBLE;
330-
}
331-
}
332-
333-
// Define the graph
334-
335-
std::vector<uint64_t> indI(n), indJ(m);
336-
std::vector<double> weights1(n), weights2(m);
337-
Digraph di(n, m);
338-
const SetupPolicy policy = make_setup_policy(n, m, n1, n2, false);
339-
NetworkSimplexSimple<Digraph,double,double, node_id_type> net(
340-
di, policy.use_arc_mixing, (int) (n + m), n * m, maxIter, numThreads
341-
);
342-
343-
// Set supply and demand, don't account for 0 values (faster)
344-
345-
cur=0;
346-
for (uint64_t i=0; i<n1; i++) {
347-
double val=*(X+i);
348-
if (val>0) {
349-
weights1[ cur ] = val;
350-
indI[cur++]=i;
351-
}
352-
}
353-
354-
// Demand is actually negative supply...
355-
356-
cur=0;
357-
for (uint64_t i=0; i<n2; i++) {
358-
double val=*(Y+i);
359-
if (val>0) {
360-
weights2[ cur ] = -val;
361-
indJ[cur++]=i;
362-
}
363-
}
364-
365-
366-
net.supplyMap(&weights1[0], (int) n, &weights2[0], (int) m);
367-
368-
setup_explicit_arc_costs(net, di, D, n2, indI, indJ, n, m);
369-
370-
// Solve the problem with the network simplex algorithm
371-
372-
int ret=net.run();
373-
if (ret==(int)net.OPTIMAL || ret==(int)net.MAX_ITER_REACHED) {
374-
*cost = 0;
375-
extract_compressed_support(
376-
net, di, INVALID, D, G, alpha, beta, cost, indI, indJ, n, n2
377-
);
378-
379-
}
380-
381-
return ret;
382-
}
383-
384302
// ============================================================================
385303
// SPARSE VERSION: Accepts edge list instead of dense cost matrix
386304
// ============================================================================

ot/lp/_barycenter_solvers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ def free_support_barycenter(
213213
Print information along iterations
214214
log : bool, optional
215215
record log if True
216-
numThreads: int or "max", optional (default=1, i.e. OpenMP is not used)
217-
If compiled with OpenMP, chooses the number of threads to parallelize.
218-
"max" selects the highest number possible.
216+
numThreads: int or "max", optional (default=1)
217+
Deprecated compatibility parameter forwarded to EMD. The network
218+
simplex solver no longer uses OpenMP, so this parameter is ignored.
219219
220220
Returns
221221
-------
@@ -349,9 +349,9 @@ def generalized_free_support_barycenter(
349349
Print information along iterations
350350
log : bool, optional
351351
record log if True
352-
numThreads: int or "max", optional (default=1, i.e. OpenMP is not used)
353-
If compiled with OpenMP, chooses the number of threads to parallelize.
354-
"max" selects the highest number possible.
352+
numThreads: int or "max", optional (default=1)
353+
Deprecated compatibility parameter forwarded to EMD. The network
354+
simplex solver no longer uses OpenMP, so this parameter is ignored.
355355
eps: Stability coefficient for the change of variable matrix inversion
356356
If the :math:`\mathbf{P}_i^T` matrices don't span :math:`\mathbb{R}^d`, the problem is ill-defined and a matrix
357357
inversion will fail. In this case one may set eps=1e-8 and get a solution anyway (which may make little sense)

ot/lp/_network_simplex.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def emd(
287287
center_dual: boolean, optional (default=True)
288288
If True, centers the dual potential using function
289289
:py:func:`ot.lp.center_ot_dual`.
290-
numThreads: int or "max", optional (default=1, i.e. OpenMP is not used)
291-
If compiled with OpenMP, chooses the number of threads to parallelize.
292-
"max" selects the highest number possible.
290+
numThreads: int or "max", optional (default=1)
291+
Deprecated compatibility parameter. The network simplex solver no
292+
longer uses OpenMP, so this parameter is ignored.
293293
check_marginals: bool, optional (default=True)
294294
If True, checks that the marginals mass are equal. If False, skips the
295295
check.
@@ -590,9 +590,9 @@ def emd2(
590590
center_dual: boolean, optional (default=True)
591591
If True, centers the dual potential using function
592592
:py:func:`ot.lp.center_ot_dual`.
593-
numThreads: int or "max", optional (default=1, i.e. OpenMP is not used)
594-
If compiled with OpenMP, chooses the number of threads to parallelize.
595-
"max" selects the highest number possible.
593+
numThreads: int or "max", optional (default=1)
594+
Deprecated compatibility parameter. The network simplex solver no
595+
longer uses OpenMP, so this parameter is ignored.
596596
check_marginals: bool, optional (default=True)
597597
If True, checks that the marginals mass are equal. If False, skips the
598598
check.

ot/lp/emd_wrap.pyx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import warnings
2121

2222
cdef extern from "EMD.h":
2323
int EMD_wrap(int n1,int n2, double *X, double *Y,double *D, double *G, double* alpha, double* beta, double *cost, uint64_t maxIter, double* alpha_init, double* beta_init) nogil
24-
int EMD_wrap_omp(int n1,int n2, double *X, double *Y,double *D, double *G, double* alpha, double* beta, double *cost, uint64_t maxIter, int numThreads) nogil
2524
int EMD_wrap_sparse(int n1, int n2, double *X, double *Y, uint64_t n_edges, uint64_t *edge_sources, uint64_t *edge_targets, double *edge_costs, uint64_t *flow_sources_out, uint64_t *flow_targets_out, double *flow_values_out, uint64_t *n_flows_out, uint64_t max_flows_out, double *alpha, double *beta, double *cost, uint64_t maxIter, double* alpha_init, double* beta_init) nogil
2625
int EMD_wrap_lazy(int n1, int n2, double *X, double *Y, double *coords_a, double *coords_b, int dim, int metric, uint64_t *flow_sources_out, uint64_t *flow_targets_out, double *flow_values_out, uint64_t *n_flows_out, uint64_t max_flows_out, double* alpha, double* beta, double *cost, uint64_t maxIter, double* alpha_init, double* beta_init) nogil
2726
cdef enum ProblemType: INFEASIBLE, OPTIMAL, UNBOUNDED, MAX_ITER_REACHED
@@ -130,10 +129,7 @@ def emd_c(np.ndarray[double, ndim=1, mode="c"] a, np.ndarray[double, ndim=1, mod
130129

131130
# calling the function
132131
with nogil:
133-
if numThreads == 1:
134-
result_code = EMD_wrap(n1, n2, <double*> a.data, <double*> b.data, <double*> M.data, <double*> G.data, <double*> alpha.data, <double*> beta.data, <double*> &cost, max_iter, alpha_init_ptr, beta_init_ptr)
135-
else:
136-
result_code = EMD_wrap_omp(n1, n2, <double*> a.data, <double*> b.data, <double*> M.data, <double*> G.data, <double*> alpha.data, <double*> beta.data, <double*> &cost, max_iter, numThreads)
132+
result_code = EMD_wrap(n1, n2, <double*> a.data, <double*> b.data, <double*> M.data, <double*> G.data, <double*> alpha.data, <double*> beta.data, <double*> &cost, max_iter, alpha_init_ptr, beta_init_ptr)
137133
return G, cost, alpha, beta, result_code
138134

139135

0 commit comments

Comments
 (0)