source: trunk/Clp/examples/driver3.cpp @ 2448

Last change on this file since 2448 was 2448, checked in by forrest, 2 months ago

add openblas one thread to driver3

File size: 3.4 KB
Line 
1// $Id: driver3.cpp 1898 2013-04-09 18:06:04Z stefan $
2// Copyright (C) 2007, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#include <cassert>
7#include <iomanip>
8
9#include "CoinPragma.hpp"
10#include "ClpSimplex.hpp"
11#ifdef ABC_INHERIT
12#include "AbcSimplex.hpp"
13#endif
14#include "CoinTime.hpp"
15
16//#############################################################################
17
18
19/************************************************************************
20
21This main program shows how to take advantage of the standalone clp in your program.
22It should perform very nearly the same as clp 
23First it reads in a model from an mps file
24Then it calls ClpMain1 passing all parameters apart from first
25Finally it prints solution
26
27************************************************************************/
28
29#ifndef ABC_INHERIT
30void ClpMain0(ClpSimplex * models);
31int ClpMain1(int argc, const char *argv[],ClpSimplex * model);
32#else
33void ClpMain0(AbcSimplex * models);
34int ClpMain1(int argc, const char *argv[],AbcSimplex * model);
35#endif
36/*
37  Somehow with some BLAS we get multithreaded by default
38  For 99.99% of problems this is not a good idea.
39  The openblas_set_num_threads(1) seems to work even with other blas
40 */
41#if CLP_USE_OPENBLAS
42extern "C" {
43void openblas_set_num_threads(int num_threads);
44}
45#endif
46int main (int argc, const char *argv[])
47{
48
49#if CLP_USE_OPENBLAS
50  openblas_set_num_threads(CLP_USE_OPENBLAS);
51#endif
52#ifndef ABC_INHERIT
53  ClpSimplex model;
54#else
55  AbcSimplex model;
56#endif
57  if (argc > 1) {
58    printf("command line - ");
59    for (int i = 0; i < argc; i++)
60      printf("%s ", argv[i]);
61    printf("\n");
62  }
63  // change defaults to match standalone solver
64  ClpMain0(&model);
65  // Read in model using argv[1]
66  // and assert that it is a clean model
67  std::string mpsFileName;
68#if defined(SAMPLEDIR)
69  mpsFileName = SAMPLEDIR "/p0033.mps";
70#else
71  if (argc < 2) {
72    fprintf(stderr, "Do not know where to find sample MPS files.\n");
73    exit(1);
74  }
75#endif
76  if (argc>=2) mpsFileName = argv[1];
77  int numMpsReadErrors = model.readMps(mpsFileName.c_str());
78  if( numMpsReadErrors != 0 )
79  {
80     printf("%d errors reading MPS file\n", numMpsReadErrors);
81     return numMpsReadErrors;
82  }
83  /* Now go into code for standalone solver
84     Could copy arguments and add -quit at end to be safe
85     but this will do
86  */
87  if (argc>2) {
88    ClpMain1(argc-1,argv+1,&model);
89  } else {
90    const char * argv2[]={"driver3","-solve","-quit"};
91    ClpMain1(3,argv2,&model);
92  }
93
94  // Print solution
95   
96  const double * solution = model.primalColumnSolution();
97  int numberColumns = model.numberColumns();
98  //const double * reducedCosts = model.dualColumnSolution();
99   
100  std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
101  std::cout<<"--------------------------------------"<<std::endl;
102   
103  for (int iColumn=0;iColumn<numberColumns;iColumn++) {
104    double value=solution[iColumn];
105    if (fabs(value)>1.0e-7) 
106      std::cout<<std::setw(6)<<iColumn<<" "<<std::setw(8)<<std::setiosflags(std::ios::left)<<model.getColumnName(iColumn)
107               <<std::resetiosflags(std::ios::adjustfield)<<std::setw(14)<<" "<<value<<std::endl;
108  }
109  std::cout<<"--------------------------------------"<<std::endl;
110 
111  std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
112  return 0;
113}   
Note: See TracBrowser for help on using the repository browser.