Bug Summary

File:OMCompiler/Compiler/runtime/HpcOmSchedulerExt_omc.cpp
Warning:line 71, column 18
Use of zero-allocated memory

Annotated Source Code

[?] Use j/k keys for keyboard navigation

HpcOmSchedulerExt_omc.cpp

1#include "openmodelica.h"
2#include "meta_modelica.h"
3#define ADD_METARECORD_DEFINITIONSstatic static
4#include "OpenModelicaBootstrappingHeader.h"
5
6#if !defined(_MSC_VER)
7#include "HpcOmSchedulerExt.cpp"
8#else
9#include "errorext.h"
10#define HPC_OM_VS() c_add_message(NULL__null, -1, ErrorType_scripting, ErrorLevel_error, "HpcOmScheduler not supported on Visual Studio.", NULL__null, 0);MMC_THROW(){longjmp(*((threadData_t*)pthread_getspecific(mmc_thread_data_key
))->mmc_jumper,1);}
;
11#endif
12
13extern "C" {
14
15extern void* HpcOmSchedulerExt_readScheduleFromGraphMl(const char *filename)
16{
17#if defined(_MSC_VER)
18 HPC_OM_VS();
19#else
20 return HpcOmSchedulerExtImpl__readScheduleFromGraphMl(filename);
21#endif
22}
23
24extern void* HpcOmSchedulerExt_scheduleMetis(modelica_metatype xadjIn, modelica_metatype adjncyIn, modelica_metatype vwgtIn, modelica_metatype adjwgtIn, int npartsIn)
25{
26#if defined(_MSC_VER)
27 HPC_OM_VS();
28#else
29 int xadjNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(xadjIn))((((((*(mmc_uint_t*)((void*)((char*)(xadjIn) - 3)))) & (7
)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(xadjIn) - 3)))
) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(xadjIn
) - 3)))) >> 10))
; //number of elements in xadj-array
30 int adjncyNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(adjncyIn))((((((*(mmc_uint_t*)((void*)((char*)(adjncyIn) - 3)))) & (
7)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(adjncyIn) - 3
)))) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(adjncyIn
) - 3)))) >> 10))
; //number of elements in adjncy-array
31 int vwgtNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(vwgtIn))((((((*(mmc_uint_t*)((void*)((char*)(vwgtIn) - 3)))) & (7
)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(vwgtIn) - 3)))
) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(vwgtIn
) - 3)))) >> 10))
; //number of elements in vwgt-array
32 int adjwgtNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(adjwgtIn))((((((*(mmc_uint_t*)((void*)((char*)(adjwgtIn) - 3)))) & (
7)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(adjwgtIn) - 3
)))) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(adjwgtIn
) - 3)))) >> 10))
; //number of elements in adjwgt-array
33 int nparts = npartsIn;
34
35 int* xadj = (int *) malloc(xadjNelts*sizeof(int));
36 int* adjncy = (int *) malloc(adjncyNelts*sizeof(int));
37 int* vwgt = (int *) malloc(vwgtNelts*sizeof(int));
38 int* adjwgt = (int *) malloc(adjwgtNelts*sizeof(int));
39
40 //setup xadj
41 for(int i=0; i<xadjNelts; i++) {
42 int xadjElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(xadjIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(xadjIn
) - 3)))->data)[i])) >> 1)
;
43 //std::cerr << "xadjElem: " << xadjElem << std::endl;
44 xadj[i] = xadjElem;
45 }
46 //setup adjncy
47 for(int i=0; i<adjncyNelts; i++) {
48 int adjncyElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(adjncyIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(adjncyIn
) - 3)))->data)[i])) >> 1)
;
49 //std::cerr << "adjncyElem: " << adjncyElem << std::endl;
50 adjncy[i] = adjncyElem;
51 }
52 //setup vwgt
53 for(int i=0; i<vwgtNelts; i++) {
54 int vwgtElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(vwgtIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(vwgtIn
) - 3)))->data)[i])) >> 1)
;
55 //std::cerr << "vwgtElem: " << vwgtElem << std::endl;
56 vwgt[i] = vwgtElem;
57 }
58 //setup adjwgt
59 for(int i=0; i<adjwgtNelts; i++) {
60 int adjwgtElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(adjwgtIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(adjwgtIn
) - 3)))->data)[i])) >> 1)
;
61 //std::cerr << "adjwgtElem: " << adjwgtElem << std::endl;
62 adjwgt[i] = adjwgtElem;
63 }
64
65 return HpcOmSchedulerExtImpl__scheduleMetis(xadj, adjncy, vwgt, adjwgt, xadjNelts, adjncyNelts, nparts);
66}
67
68extern void* HpcOmSchedulerExt_schedulehMetis(modelica_metatype xadjIn, modelica_metatype adjncyIn, modelica_metatype vwgtIn, modelica_metatype adjwgtIn, int npartsIn)
69{
70
71 int vwgtsNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(xadjIn))((((((*(mmc_uint_t*)((void*)((char*)(xadjIn) - 3)))) & (7
)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(xadjIn) - 3)))
) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(xadjIn
) - 3)))) >> 10))
; //number of elements in xadj-array
72 int eptrNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(adjncyIn))((((((*(mmc_uint_t*)((void*)((char*)(adjncyIn) - 3)))) & (
7)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(adjncyIn) - 3
)))) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(adjncyIn
) - 3)))) >> 10))
; //number of elements in adjncy-array
73 int eintNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(vwgtIn))((((((*(mmc_uint_t*)((void*)((char*)(vwgtIn) - 3)))) & (7
)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(vwgtIn) - 3)))
) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(vwgtIn
) - 3)))) >> 10))
; //number of elements in vwgt-array
74 int hewgtsNelts = (int)MMC_HDRSLOTS(MMC_GETHDR(adjwgtIn))((((((*(mmc_uint_t*)((void*)((char*)(adjwgtIn) - 3)))) & (
7)) == 5)) ? ((((*(mmc_uint_t*)((void*)((char*)(adjwgtIn) - 3
)))) >> (3+3))) : (((*(mmc_uint_t*)((void*)((char*)(adjwgtIn
) - 3)))) >> 10))
; //number of elements in adjwgt-array
75 int nparts = npartsIn;
76
77 int* vwgts = (int *) malloc(vwgtsNelts*sizeof(int));
78 int* eptr = (int *) malloc(eptrNelts*sizeof(int));
79 int* eint = (int *) malloc(eintNelts*sizeof(int));
80 int* hewgts = (int *) malloc(hewgtsNelts*sizeof(int));
81
82 //setup xadj
83 for(int i=0; i<vwgtsNelts; i++) {
1
Assuming 'i' is >= 'vwgtsNelts'
2
Loop condition is false. Execution continues on line 89
84 int xadjElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(xadjIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(xadjIn
) - 3)))->data)[i])) >> 1)
;
85 std::cerr << "vwgtsElem: " << xadjElem << std::endl;
86 vwgts[i] = xadjElem;
87 }
88 //setup adjncy
89 for(int i=0; i<eptrNelts; i++) {
3
Assuming 'i' is >= 'eptrNelts'
4
Loop condition is false. Execution continues on line 95
90 int adjncyElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(adjncyIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(adjncyIn
) - 3)))->data)[i])) >> 1)
;
91 std::cerr << "eptrElem: " << adjncyElem << std::endl;
92 eptr[i] = adjncyElem;
93 }
94 //setup vwgt
95 for(int i=0; i<eintNelts; i++) {
5
Assuming 'i' is >= 'eintNelts'
6
Loop condition is false. Execution continues on line 101
96 int vwgtElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(vwgtIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(vwgtIn
) - 3)))->data)[i])) >> 1)
;
97 std::cerr << "eintElem: " << vwgtElem << std::endl;
98 eint[i] = vwgtElem;
99 }
100 //setup adjwgt
101 for(int i=0; i<hewgtsNelts; i++) {
7
Assuming 'i' is >= 'hewgtsNelts'
8
Loop condition is false. Execution continues on line 106
102 int adjwgtElem = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(adjwgtIn)[i])(((mmc_sint_t) ((((struct mmc_struct*)((void*)((char*)(adjwgtIn
) - 3)))->data)[i])) >> 1)
;
103 std::cerr << "adjwgtElem: " << adjwgtElem << std::endl;
104 hewgts[i] = adjwgtElem;
105 }
106 return HpcOmSchedulerExtImpl__scheduleMetis(vwgts, eptr, eint, hewgts, vwgtsNelts, eptrNelts, nparts);
9
Calling 'HpcOmSchedulerExtImpl__scheduleMetis'
107#endif
108}
109
110}

./HpcOmSchedulerExt.cpp

1#include "TaskGraphResultsCmp.h"
2#include "omc_config.h"
3#include <iostream>
4
5#if USE_PATOH0
6#include "patoh.h"
7#endif
8
9#if USE_METIS1
10#include "metis.h"
11#endif
12
13using namespace std;
14
15
16
17void* HpcOmSchedulerExtImpl__readScheduleFromGraphMl(const char *filename)
18{
19 void *res = mmc_mk_nil()((void*)((char*)(&(mmc_nil).header) + 3));
20 std::string errorMsg = std::string("");
21 Graph g;
22 GraphMLParser parser;
23
24 if (!GraphMLParser::CheckIfFileExists(filename))
25 {
26 std::cerr << "File " << filename << " not found" << std::endl;
27 errorMsg = "File '";
28 errorMsg += std::string(filename);
29 errorMsg += "' does not exist";
30 res = mmc_mk_cons(mmc_mk_scon(errorMsg.c_str()), mmc_mk_nil()((void*)((char*)(&(mmc_nil).header) + 3)));
31 return res;
32 }
33
34 parser.ParseGraph(&g, filename,NodeComparator(&NodeComparator::CompareNodeNamesInt), &errorMsg);
35
36 std::list<Node*> sortedNodeList = std::list<Node*>(g.nodes.begin(), g.nodes.end());
37 sortedNodeList.sort(NodeComparator(&NodeComparator::CompareNodeTaskIdsInt));
38
39 for (std::list<Node*>::iterator iter = sortedNodeList.begin(); iter != sortedNodeList.end(); iter++) {
40 //std::cerr << "Node " << (*iter)->taskId << " th " << atoi((*iter)->threadId.substr(3).c_str()) << std::endl;
41
42 if((*iter)->threadId.size() < 3)
43 continue;
44 res = mmc_mk_cons(mmc_mk_icon(atoi((*iter)->threadId.substr(3).c_str())), res);
45 }
46 return res;
47}
48
49#if USE_METIS1
50void* HpcOmSchedulerExtImpl__scheduleMetis(int* xadj, int* adjncy, int* vwgt, int* adjwgt, int xadjCount, int adjncyCount, int nparts)
51{
52 void *res = mmc_mk_nil()((void*)((char*)(&(mmc_nil).header) + 3));
53 int nvert=xadjCount-1;
54 idx_t met_nvtxs=xadjCount-1;
55 idx_t met_ncon=1;
56 //double * part=new double[nvert];
57 idx_t * met_xadj=new idx_t[nvert+1]; //={0,2,5,8,11,13,16,20,24,28,31,33,36,39,42,44};
10
Memory is allocated
58 idx_t * met_adjncy=new idx_t[xadj[nvert]];//={1,5,0,2,6,1,3,7,2,4,8,3,9,0,6,10,1,5,7,11,2,6,8,12,3,7,9,13,4,8,14,5,11,6,10,12,2,7,11,13,8,12,14,9,13};
59 idx_t * met_vwgt=new idx_t[nvert]; //={0,2,5,8,11,13,16,20,24,28,31,33,36,39,42,44};
60 idx_t * met_adjwgt=new idx_t[xadj[nvert]];
61 idx_t met_objval;
62 idx_t * met_part=new idx_t[nvert];
63 idx_t met_nparts=nparts;
64 int returnval;
65
66 for(int i=0; i<nvert; i++) {
11
Loop condition is false. Execution continues on line 71
67 met_xadj[i]=xadj[i];
68 met_vwgt[i]=vwgt[i];
69// cout<<met_xadj[i]<<" "<<met_vwgt[i]<<endl;
70 }
71 met_xadj[nvert]=xadj[nvert];
12
Use of zero-allocated memory
72// cout<<"test: "<<met_xadj[nvert+4]<<endl;
73 for(int i=0; i<xadj[nvert]; i++) {
74 met_adjncy[i]=adjncy[i];
75 met_adjwgt[i]=adjwgt[i];
76// cout<<met_adjncy[i]<<" "<<met_adjwgt[i]<<endl;
77 }
78 int * result=new int[nvert];
79 returnval=METIS_PartGraphKway(&met_nvtxs,&met_ncon,met_xadj,met_adjncy,met_vwgt,NULL__null,met_adjwgt,&met_nparts,NULL__null,NULL__null,NULL__null,&met_objval,met_part);
80 for(int i=nvert-1; i>=0; i--) {
81 result[i]=met_part[i]+1;
82 res = mmc_mk_cons(mmc_mk_icon(result[i]),res);
83 }
84 delete[] met_xadj;
85 delete[] met_adjncy;
86 delete[] met_vwgt;
87 delete[] met_adjwgt;
88 delete[] met_part;
89 return res;
90}
91#elif USE_PATOH0
92void* HpcOmSchedulerExtImpl__scheduleMetis(int* vwgts, int* eptr, int* eint, int* hewgts, int vwgtsNelts, int eptrNelts, int nparts)
93{
94 void *res = mmc_mk_nil()((void*)((char*)(&(mmc_nil).header) + 3));
95 int * result=new int[vwgtsNelts];
96 PaToH_Parameters args;
97 int c, n, nconst, cut, *partweights;
98 PaToH_Initialize_Parameters(&args, PATOH_CONPART, PATOH_SUGPARAM_DEFAULT);
99 args._k = nparts;
100 partweights = new int[nparts];
101 PaToH_Alloc(&args, vwgtsNelts, eptrNelts-1, 1, vwgts, NULL__null, eptr, eint);
102 PaToH_Part(&args, vwgtsNelts, eptrNelts-1, 1, 0, vwgts, NULL__null,eptr, eint, NULL__null, result, partweights, &cut);
103 PaToH_Free();
104
105
106 for(int i=vwgtsNelts-1; i>=0; i--) {
107 res = mmc_mk_cons(mmc_mk_icon(result[i]+1),res);
108 }
109 cout<<endl;
110 delete [] result;
111 delete [] partweights;
112 return res;
113}
114#else
115void* HpcOmSchedulerExtImpl__scheduleMetis(int* vwgts, int* eptr, int* eint, int* hewgts, int vwgtsNelts, int eptrNelts, int nparts)
116{
117 std::cerr<<"OpenModelica was not compiled with PATOH or METIS."<<std::endl;
118 return mmc_mk_nil()((void*)((char*)(&(mmc_nil).header) + 3));
119}
120#endif