Skip to content

Commit

Permalink
- Merge some code in BackendDAEEXT so we do not have a different vers…
Browse files Browse the repository at this point in the history
…ion for bootstrapped (it was broken, causing errors in libc malloc, making the process into a zombie)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14138 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 29, 2012
1 parent 650b06d commit 5eb3d3d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 133 deletions.
68 changes: 68 additions & 0 deletions Compiler/runtime/BackendDAEEXT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ static std::vector<int> f;
using namespace std;

extern "C" {
#include "matchmaker.h"

static unsigned int n=0;
static unsigned int m=0;
static int* match=NULL;
static int* row_match=NULL;
static int* col_ptrs=NULL;
static int* col_ids=NULL;

void BackendDAEEXTImpl__initMarks(int nvars, int neqns)
{
Expand Down Expand Up @@ -221,4 +229,64 @@ int BackendDAEEXTImpl__getV(int i)
return v[i-1];
}

void BackendDAEExtImpl__matching(int nvars, int neqns, int matchingID, int cheapID, double relabel_period, int clear_match)
{
int i=0;
if (clear_match==0){
if (neqns>n) {
int* tmp = (int*) malloc(neqns * sizeof(int));
if(match)
{
memcpy(tmp,match,n*sizeof(int));
free(match);
match = tmp;
for (i = n; i < neqns; i++) {
match[i] = -1;
}
} else {
match = (int*) malloc(neqns * sizeof(int));
memset(match,-1,neqns * sizeof(int));
}
n = neqns;
}
if (nvars>m) {
int* tmp = (int*) malloc(nvars * sizeof(int));
if(row_match)
{
memcpy(tmp,row_match,m*sizeof(int));
free(row_match);
row_match = tmp;
for (i = m; i < nvars; i++) {
row_match[i] = -1;
}
} else {
row_match = (int*) malloc(nvars * sizeof(int));
memset(row_match,-1,nvars * sizeof(int));
}
m = nvars;
}
}
else {
if (neqns>n) {
if (match) free(match);
match = (int*) malloc(neqns * sizeof(int));
memset(match,-1,neqns * sizeof(int));
} else {
memset(match,-1,n * sizeof(int));
}
n = neqns;
if (nvars>m) {
if (row_match) free(row_match);
row_match = (int*) malloc(nvars * sizeof(int));
memset(row_match,-1,nvars * sizeof(int));
} else {
memset(row_match,-1,m * sizeof(int));
}
m = nvars;
}
if ((match != NULL) && (row_match != NULL)) {
matching(col_ptrs,col_ids,match,row_match,neqns,nvars,matchingID,cheapID,relabel_period,clear_match);
}
}

}
69 changes: 1 addition & 68 deletions Compiler/runtime/BackendDAEEXT_omc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
#include "BackendDAEEXT.cpp"
#include <stdlib.h>

extern "C" {
#include "matchmaker.h"
}

extern "C" {

extern int BackendDAEEXT_getVMark(int _inInteger)
Expand Down Expand Up @@ -113,13 +109,6 @@ extern void BackendDAEEXT_vMark(int _inInteger)
BackendDAEEXTImpl__vMark(_inInteger);
}

unsigned int n=0;
unsigned int m=0;
int* match=NULL;
int* row_match=NULL;
int* col_ptrs=NULL;
int* col_ids=NULL;

extern void BackendDAEEXT_setIncidenceMatrix(modelica_integer nvars, modelica_integer neqns, modelica_integer nz, modelica_metatype incidencematrix)
{
int i=0;
Expand Down Expand Up @@ -149,63 +138,7 @@ extern void BackendDAEEXT_setIncidenceMatrix(modelica_integer nvars, modelica_in
extern void BackendDAEEXT_matching(modelica_integer nv, modelica_integer ne, modelica_integer matchingID, modelica_integer cheapID, modelica_real relabel_period, modelica_integer clear_match)
{
int i=0;
if (clear_match==0){
if (ne>n) {
int* tmp = (int*) malloc(ne * sizeof(int));
if(match)
{
memcpy(tmp,match,n*sizeof(int));
free(match);
match = tmp;
for (i = n; i < ne; i++) {
match[i] = -1;
}
}
else {
match = (int*) malloc(ne * sizeof(int));
memset(match,-1,ne * sizeof(int));
}
n = ne;
}
if (nv>m) {
int* tmp = (int*) malloc(nv * sizeof(int));
if(row_match)
{
memcpy(tmp,row_match,m*sizeof(int));
free(row_match);
row_match = tmp;
for (i = m; i < nv; i++) {
row_match[i] = -1;
}
}
else {
row_match = (int*) malloc(nv * sizeof(int));
memset(row_match,-1,nv * sizeof(int));
}
m = nv;
}
}
else {
if (ne>n) {
if (match) free(match);
match = (int*) malloc(ne * sizeof(int));
memset(match,-1,ne * sizeof(int));
} else {
memset(match,-1,n * sizeof(int));
}
n = ne;
if (nv>m) {
if (row_match) free(row_match);
row_match = (int*) malloc(nv * sizeof(int));
memset(row_match,-1,nv * sizeof(int));
} else {
memset(row_match,-1,m * sizeof(int));
}
m = nv;
}
if ((match != NULL) && (row_match != NULL)) {
matching(col_ptrs,col_ids,match,row_match,nv,ne,matchingID,cheapID,relabel_period,clear_match);
}
BackendDAEExtImpl__matching(nv, ne, matchingID, cheapID, relabel_period, clear_match);
}

extern void BackendDAEEXT_getAssignment(modelica_metatype ass1, modelica_metatype ass2)
Expand Down
66 changes: 1 addition & 65 deletions Compiler/runtime/BackendDAEEXT_rml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@


extern "C" {
#include "matchmaker.h"
#include "rml.h"
}

Expand Down Expand Up @@ -252,13 +251,6 @@ RML_BEGIN_LABEL(BackendDAEEXT__getV)
}
RML_END_LABEL

unsigned int n=0;
unsigned int m=0;
int* match=NULL;
int* row_match=NULL;
int* col_ptrs=NULL;
int* col_ids=NULL;

RML_BEGIN_LABEL(BackendDAEEXT__setIncidenceMatrix)
{
int i=0;
Expand Down Expand Up @@ -292,69 +284,13 @@ RML_END_LABEL

RML_BEGIN_LABEL(BackendDAEEXT__matching)
{
int i=0;
int nvars = RML_UNTAGFIXNUM(rmlA0);
int neqns = RML_UNTAGFIXNUM(rmlA1);
int matchingID = RML_UNTAGFIXNUM(rmlA2);
int cheapID = RML_UNTAGFIXNUM(rmlA3);
double relabel_period = RML_UNTAGFIXNUM(rmlA4);
int clear_match = RML_UNTAGFIXNUM(rmlA5);

if (clear_match==0){
if (neqns>n) {
int* tmp = (int*) malloc(neqns * sizeof(int));
if(match)
{
memcpy(tmp,match,n*sizeof(int));
free(match);
match = tmp;
for (i = n; i < neqns; i++) {
match[i] = -1;
}
} else {
match = (int*) malloc(neqns * sizeof(int));
memset(match,-1,neqns * sizeof(int));
}
n = neqns;
}
if (nvars>m) {
int* tmp = (int*) malloc(nvars * sizeof(int));
if(row_match)
{
memcpy(tmp,row_match,m*sizeof(int));
free(row_match);
row_match = tmp;
for (i = m; i < nvars; i++) {
row_match[i] = -1;
}
} else {
row_match = (int*) malloc(nvars * sizeof(int));
memset(row_match,-1,nvars * sizeof(int));
}
m = nvars;
}
}
else {
if (neqns>n) {
if (match) free(match);
match = (int*) malloc(neqns * sizeof(int));
memset(match,-1,neqns * sizeof(int));
} else {
memset(match,-1,n * sizeof(int));
}
n = neqns;
if (nvars>m) {
if (row_match) free(row_match);
row_match = (int*) malloc(nvars * sizeof(int));
memset(row_match,-1,nvars * sizeof(int));
} else {
memset(row_match,-1,m * sizeof(int));
}
m = nvars;
}
if ((match != NULL) && (row_match != NULL)) {
matching(col_ptrs,col_ids,match,row_match,neqns,nvars,matchingID,cheapID,relabel_period,clear_match);
}
BackendDAEExtImpl__matching(nvars, neqns, matchingID, cheapID, relabel_period, clear_match);
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand Down

0 comments on commit 5eb3d3d

Please sign in to comment.