Can be used openMP with Cplex libraries?

General OpenMP discussion

Can be used openMP with Cplex libraries?

Postby eukmij » Thu Jan 16, 2020 11:15 am

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?
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?

Postby MarkB » Wed Jan 22, 2020 5:12 am

Can you explain exactly what you mean by compatible here? A what is your problem - compile time failure, run time failure, something else?
MarkB
 
Posts: 787
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Can be used openMP with Cplex libraries?

Postby eukmij » Wed Jan 22, 2020 11:49 am

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[i].Solve(th);
}
#pragma omp critical
{
solvedAll = solvedAll && solvedHere;
}
}
cout << (solvedAll ? "Success" : "Fail") << endl;
return 0;
}
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?

Postby MarkB » Thu Jan 30, 2020 12:51 pm

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).
MarkB
 
Posts: 787
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Can be used openMP with Cplex libraries?

Postby eukmij » Fri Jan 31, 2020 1:41 am

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.
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?

Postby MarkB » Fri Jan 31, 2020 12:32 pm

I think you also need -fopenmp in your CCOPT flags.
MarkB
 
Posts: 787
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Can be used openMP with Cplex libraries?

Postby eukmij » Sat Feb 01, 2020 11:14 am

That was the trouble!
Thank you very much for your help.
eukmij
 
Posts: 4
Joined: Wed Jan 15, 2020 12:30 pm
Location: University of the Basque Country


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 3 guests

cron