source: trunk/Clp/src/ClpMain.cpp @ 2030

Last change on this file since 2030 was 2030, checked in by forrest, 5 years ago

fix some ampl stuff, add ClpSolver? and a few fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/* $Id: ClpMain.cpp 2030 2014-04-15 15:54:11Z forrest $ */
2// Copyright (C) 2002, 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 "CoinPragma.hpp"
7
8#include "AbcCommon.hpp"
9#include "ClpSimplex.hpp"
10#ifdef ABC_INHERIT
11#include "AbcSimplex.hpp"
12#endif
13#ifndef ABC_INHERIT
14void ClpMain0(ClpSimplex * models);
15int ClpMain1(int argc, const char *argv[],ClpSimplex * model);
16#else
17void ClpMain0(AbcSimplex * models);
18int ClpMain1(int argc, const char *argv[],AbcSimplex * model);
19#endif
20//#define CILK_TEST
21#ifdef CILK_TEST
22static void cilkTest();
23#endif
24int
25#if defined(_MSC_VER)
26__cdecl
27#endif // _MSC_VER
28main (int argc, const char *argv[])
29{
30#ifdef CILK_TEST
31  cilkTest();
32#endif
33#ifndef ABC_INHERIT
34  ClpSimplex * models = new ClpSimplex[1];
35#else
36  AbcSimplex * models = new AbcSimplex[1];
37#endif
38  std::cout << "Coin LP version " << CLP_VERSION
39            << ", build " << __DATE__ << std::endl;
40  // Print command line
41  if (argc > 1) {
42    printf("command line - ");
43    for (int i = 0; i < argc; i++)
44      printf("%s ", argv[i]);
45    printf("\n");
46  }
47  ClpMain0(models);
48  int returnCode = ClpMain1(argc, argv,models);
49  delete [] models;
50  return returnCode;
51}
52/*
53  Version 1.00.00 October 13 2004.
54  1.00.01 October 18.  Added basis handling helped/prodded by Thorsten Koch.
55  Also modifications to make faster with sbb (I hope I haven't broken anything).
56  1.00.02 March 21 2005.  Redid ClpNonLinearCost to save memory also redid
57  createRim to try and improve cache characteristics.
58  1.00.03 April 8 2005.  Added Volume algorithm as crash and made code more
59  robust on testing.  Also added "either" and "tune" algorithm.
60  1.01.01 April 12 2005.  Decided to go to different numbering.  Backups will
61  be last 2 digits while middle 2 are for improvements.  Still take a long
62  time to get to 2.00.01
63  1.01.02 May 4 2005.  Will be putting in many changes - so saving stable version
64  1.02.01 May 6 2005.  Lots of changes to try and make faster and more stable in
65  branch and cut.
66  1.02.02 May 19 2005.  Stuff for strong branching and some improvements to simplex
67  1.03.01 May 24 2006.  Lots done but I can't remember what!
68  1.03.03 June 13 2006.  For clean up after dual perturbation
69  1.04.01 June 26 2007.  Lots of changes but I got lazy
70  1.05.00 June 27 2007.  This is trunk so when gets to stable will be 1.5
71  1.11.00 November 5 2009 (Guy Fawkes) - OSL factorization and better ordering
72 */
73#ifdef CILK_TEST
74// -*- C++ -*-
75
76/*
77 * cilk-for.cilk
78 *
79 * Copyright (c) 2007-2008 Cilk Arts, Inc.  55 Cambridge Street,
80 * Burlington, MA 01803.  Patents pending.  All rights reserved. You may
81 * freely use the sample code to guide development of your own works,
82 * provided that you reproduce this notice in any works you make that
83 * use the sample code.  This sample code is provided "AS IS" without
84 * warranty of any kind, either express or implied, including but not
85 * limited to any implied warranty of non-infringement, merchantability
86 * or fitness for a particular purpose.  In no event shall Cilk Arts,
87 * Inc. be liable for any direct, indirect, special, or consequential
88 * damages, or any other damages whatsoever, for any use of or reliance
89 * on this sample code, including, without limitation, any lost
90 * opportunity, lost profits, business interruption, loss of programs or
91 * data, even if expressly advised of or otherwise aware of the
92 * possibility of such damages, whether in an action of contract,
93 * negligence, tort, or otherwise.
94 *
95 * This file demonstrates a Cilk++ for loop
96 */
97
98#include <cilk/cilk.h>
99//#include <cilk/cilkview.h>
100#include <cilk/reducer_max.h>
101#include <cstdlib>
102#include <iostream>
103
104// cilk_for granularity.
105#define CILK_FOR_GRAINSIZE 128
106
107double dowork(double i)
108{
109    // Waste time:
110    int j;
111    double k = i;
112    for (j = 0; j < 50000; ++j) {
113        k += k / ((j + 1) * (k + 1));
114    }
115
116    return k;
117}
118static void doSomeWork(double * a,int low, int high)
119{
120  if (high-low>300) {
121    int mid=(high+low)>>1;
122    cilk_spawn doSomeWork(a,low,mid);
123    doSomeWork(a,mid,high);
124    cilk_sync;
125  } else {
126    for(int i = low; i < high; ++i) {
127      a[i] = dowork(a[i]);
128    }
129  }
130}
131
132void cilkTest()
133{
134    unsigned int n = 10000;
135    //cilk::cilkview cv;
136
137
138    double* a = new double[n];
139
140    for(unsigned int i = 0; i < n; i++) {
141        // Populate A
142        a[i] = (double) ((i * i) % 1024 + 512) / 512;
143    }
144
145    std::cout << "Iterating over " << n << " integers" << std::endl;
146
147    //cv.start();
148#if 1
149    //#pragma cilk_grainsize=CILK_FOR_GRAINSIZE
150    cilk_for(unsigned int i = 0; i < n; ++i) {
151        a[i] = dowork(a[i]);
152    }
153#else
154    doSomeWork(a,0,n);
155#endif
156    int * which =new int[n];
157    unsigned int n2=n>>1;
158    for (int i=0;i<n2;i++) 
159      which[i]=n-2*i;
160    cilk::reducer_max_index<int,double> maximumIndex(-1,0.0);
161    cilk_for(unsigned int i = 0; i < n2; ++i) {
162      int iWhich=which[i];
163      maximumIndex.calc_max(iWhich,a[iWhich]);
164    }
165    int bestIndex=maximumIndex.get_index();
166    int bestIndex2=-1;
167    double largest=0.0;
168    cilk_for(unsigned int i = 0; i < n2; ++i) {
169      int iWhich=which[i];
170      if (a[iWhich]>largest) {
171        bestIndex2=iWhich;
172        largest=a[iWhich];
173      }
174    }
175    assert (bestIndex==bestIndex2);
176    //cv.stop();
177    //cv.dump("cilk-for-results", false);
178
179    //std::cout << cv.accumulated_milliseconds() / 1000.f << " seconds" << std::endl;
180
181    exit(0);
182}
183#endif
Note: See TracBrowser for help on using the repository browser.