Can be used openMP with Cplex libraries?

General OpenMP discussion
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help: https://stackoverflow.com/questions/tagged/openmp
Locked
eukmij
Posts: 4
Joined: Wed Jan 15, 2020 12:30 pm
Location: University of the Basque Country

Can be used openMP with Cplex libraries?

Post by eukmij »

Is compatible openMP with the Cplex libraries? I have not been able to find any c++ code example that works when ilcplex/ilocplex.h is used. Do you know some example? Is there bibliography about that matter?

MarkB
Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Can be used openMP with Cplex libraries?

Post by MarkB »

Can you explain exactly what you mean by compatible here? A what is your problem - compile time failure, run time failure, something else?

eukmij
Posts: 4
Joined: Wed Jan 15, 2020 12:30 pm
Location: University of the Basque Country

Re: Can be used openMP with Cplex libraries?

Post by eukmij »

Thank you for your answer.
When I execute my pilot code with the instruction omp_get_num_threads() it gives me only 1 thread.
Next, some instructions are introduced in order to know the framework:
int main(void)
{
for (int i = 0; i < NMax; i++)
solvers.push_back(Solver(i, FileName));
char stop_flag;
bool solvedAll = true;
#pragma omp parallel num_threads(4)
cout<<"omp_get_num_threads = "<<omp_get_num_threads()<<endl;
{
bool solvedHere = true;
int th ;
#pragma omp for
for (int i = 0; i < NMax; i++) {
th = omp_get_thread_num();
solvedHere = solvedHere && solvers.Solve(th);
}
#pragma omp critical
{
solvedAll = solvedAll && solvedHere;
}
}
cout << (solvedAll ? "Success" : "Fail") << endl;
return 0;
}

MarkB
Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Can be used openMP with Cplex libraries?

Post by MarkB »

It looks like you have a misplaced curly brace here: try

Code: Select all

#pragma omp parallel num_threads(4)
{
cout<<"omp_get_num_threads = "<<omp_get_num_threads()<<endl;
instead of

Code: Select all

#pragma omp parallel num_threads(4)
cout<<"omp_get_num_threads = "<<omp_get_num_threads()<<endl;
{
(Your code is legal OpenMP, but the parallel directive applies to the following structured block, which in this case is just the cout statement: the following code inside the { } will be executed sequentially).

eukmij
Posts: 4
Joined: Wed Jan 15, 2020 12:30 pm
Location: University of the Basque Country

Re: Can be used openMP with Cplex libraries?

Post by eukmij »

I have done

#pragma omp parallel num_threads(4)
{
cout<<"omp_get_num_threads = "<<omp_get_num_threads()<<endl;
cout<<"omp_get_num_procs = "<<omp_get_num_procs()<<endl;

but the result is the same:

omp_get_num_threads = 1
omp_get_num_procs = 8
Hello from thread 0
Objective value 0
Hello from thread 0
Objective value 0
Hello from thread 0
Objective value 0
Hello from thread 0
Objective value 0
Success

where the first line should be omp_get_num_threads = 8 and omp_get_thread_num() must not be 0 in all the cases.

On the other hand, I use this Makefile:

SYSTEM = x86-64_linux
LIBFORMAT = static_pic

CPLEXDIR = ../../cplex127/cplex
CONCERTDIR = ../../cplex127/concert

# ---------------------------------------------------------------------
# Compiler selection
# ---------------------------------------------------------------------

CCC = g++

# ---------------------------------------------------------------------
# Compiler options
# ---------------------------------------------------------------------

CCOPT = -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD

# ---------------------------------------------------------------------
# Link options and libraries
# ---------------------------------------------------------------------

CPLEXLIBDIR = $(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CONCERTLIBDIR = $(CONCERTDIR)/lib/$(SYSTEM)/$(LIBFORMAT)

CCLNFLAGS = -m64 -O -L$(CPLEXLIBDIR) -lilocplex -lcplex -L$(CONCERTLIBDIR) -lconcert -lm -pthread -pg -fopenmp

CONCERTINCDIR = $(CONCERTDIR)/include
CPLEXINCDIR = $(CPLEXDIR)/include

CCFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)

prueba4: prueba4.o
$(CCC) $(CCFLAGS) prueba4.o -o prueba4 $(CCLNFLAGS)
prueba4.o: prueba4.cpp
$(CCC) -c $(CCFLAGS) prueba4.cpp -o prueba4.o

Are ill designed my Makefile options?

Thank you very much for your help.

MarkB
Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Can be used openMP with Cplex libraries?

Post by MarkB »

I think you also need -fopenmp in your CCOPT flags.

eukmij
Posts: 4
Joined: Wed Jan 15, 2020 12:30 pm
Location: University of the Basque Country

Re: Can be used openMP with Cplex libraries?

Post by eukmij »

That was the trouble!
Thank you very much for your help.

Locked