solver_mlmtiluc2.cpp 232 KB
Newer Older
Kirill Terekhov's avatar
Kirill Terekhov committed
1
2
3
4
5
6
#define _CRT_SECURE_NO_WARNINGS
#include "inmost_solver.h"
#if defined(USE_SOLVER)
#include "solver_mlmtiluc2.hpp"
#include <sstream>
#include <deque>
7
#include <iomanip>
8

9
#include "../../../Misc/utils.h"
Kirill Terekhov's avatar
Kirill Terekhov committed
10
11
12
13
14
15
16
17
//#define USE_OMP

using namespace INMOST;

#ifndef DEFAULT_TAU
#define DEFAULT_TAU 0.01
#endif

18
19
20
21
22
#if defined(USE_OMP)
#define USE_OMP_FACT
#endif //USE_OMP

//~ #undef USE_OMP
Kirill Terekhov's avatar
Kirill Terekhov committed
23

24

25
//#define REORDER_RCM
26
#define REORDER_WRCM
27
//~ #define REORDER_BRCM
Kirill Terekhov's avatar
Kirill Terekhov committed
28
#if defined(USE_SOLVER_METIS)
29
//#define REORDER_METIS_ND
Kirill Terekhov's avatar
Kirill Terekhov committed
30
31
32
33
34
#endif
#if defined(USE_SOLVER_MONDRIAAN)
//#define REORDER_MONDRIAAN
#endif

35
static int run_nd = 2; //1 - unsymmetric dissection before mpt, 2 - symmetric dissection after mpt
Kirill Terekhov's avatar
Kirill Terekhov committed
36
static bool run_mpt = true;
37
static bool reorder_b = true;
Kirill Terekhov's avatar
Kirill Terekhov committed
38
39
static bool rescale_b = true;
static bool allow_pivot = true;
40
static bool print_mem = false;
41
static bool show_summary = true;
42
const INMOST_DATA_ENUM_TYPE UNDEF = ENUMUNDEF, EOL = ENUMUNDEF - 1;
Kirill Terekhov's avatar
Kirill Terekhov committed
43
44


45
//~ #define EQUALIZE_1NORM
46
//#define EQUALIZE_2NORM
47
#define EQUALIZE_IDOMINANCE
Kirill Terekhov's avatar
Kirill Terekhov committed
48

49
//#define PREMATURE_DROPPING
50
//#define PIVOT_THRESHOLD
Kirill Terekhov's avatar
Kirill Terekhov committed
51
//#define DIAGONAL_PERTURBATION
52
53
54
55
const double rpert = 1.0e-6;
const double apert = 1.0e-8;
#define ILUC2
#define ILUC2_SCHUR
56

Kirill Terekhov's avatar
Kirill Terekhov committed
57
//#define PIVOT_COND_DEFAULT 0.1/tau
58
#define PIVOT_COND_DEFAULT 1.0e+2
Kirill Terekhov's avatar
Kirill Terekhov committed
59
#define PIVOT_DIAG_DEFAULT 1.0e+5
60
61
//#define SCHUR_DROPPING_LF
//#define SCHUR_DROPPING_EU
62
63
64
#define SCHUR_DROPPING_S
#define SCHUR_DROPPING_LF_PREMATURE
#define SCHUR_DROPPING_EU_PREMATURE
65
// #define SCHUR_DROPPING_S_PREMATURE
Kirill Terekhov's avatar
Kirill Terekhov committed
66
67
#define CONDITION_PIVOT

68
#if defined(USE_SOLVER_METIS)
Kirill Terekhov's avatar
Kirill Terekhov committed
69
#define METIS_EXPORT
Kirill Terekhov's avatar
Kirill Terekhov committed
70
71
#include "metis.h"
#endif
72

Kirill Terekhov's avatar
Kirill Terekhov committed
73
74
75
76
77
78
79
#if defined(REORDER_ZOLTAN_HUND)
#include <zoltan.h>
#endif
#if defined(REORDER_MONDRIAAN)
#include <Mondriaan.h>
#endif

80
81
82
83
84
85
86
87
88
	template<typename T>
	std::ostream & fmt(std::ostream & in, const T & value, int width, int precision)
	{
		std::ios save(NULL);
		save.copyfmt(in);
		in << std::fixed << std::setw(width) << std::setprecision(precision) << value;
		std::cout.copyfmt(save);
		return in;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
89
90
91
92
93


	void MLMTILUC_preconditioner::ReorderEF(INMOST_DATA_ENUM_TYPE wbeg,
											INMOST_DATA_ENUM_TYPE wend,
											interval<INMOST_DATA_ENUM_TYPE, bool> & donePQ,
94
95
											const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localP,
											const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localQ)
Kirill Terekhov's avatar
Kirill Terekhov committed
96
97
98
99
	{
		INMOST_DATA_ENUM_TYPE i, k, l;
		if( !E_Address.empty() )
		{
100
			for(k = wbeg; k < wend; ++k) donePQ[k] = false;
Kirill Terekhov's avatar
Kirill Terekhov committed
101
102
103
104
105
106
107
108
109
110
111
			i = wbeg;
			while (i < wend)
			{
				if (donePQ[i]) i++;
				else
				{
					if (localP[i] != i)
					{
						k = i;
						do
						{
112
							for(l = 0; l < E_Address.size(); ++l)
113
114
115
116
117
							{
								Interval t = E_Address[l]->at(i);
								E_Address[l]->at(i) = E_Address[l]->at(localP[k]);
								E_Address[l]->at(localP[k]) = t;
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
118
119
120
121
122
123
124
125
126
127
							donePQ[localP[k]] = true;
							k = localP[k];
						} while (k != i);
					}
					donePQ[i] = true;
				}
			}
		}
		if( !F_Address.empty() )
		{
128
			for(k = wbeg; k < wend; ++k) donePQ[k] = false;
Kirill Terekhov's avatar
Kirill Terekhov committed
129
130
131
132
133
134
135
136
137
138
139
			i = wbeg;
			while (i < wend)
			{
				if (donePQ[i]) i++;
				else
				{
					if (localQ[i] != i)
					{
						k = i;
						do
						{
140
							for(l = 0; l < F_Address.size(); ++l)
141
142
143
144
145
							{
								Interval t = F_Address[l]->at(i);
								F_Address[l]->at(i) = F_Address[l]->at(localQ[k]);
								F_Address[l]->at(localQ[k]) = t;
							}
Kirill Terekhov's avatar
Kirill Terekhov committed
146
147
148
149
150
151
152
153
154
155
							donePQ[localQ[k]] = true;
							k = localQ[k];
						} while (k != i);
					}
					donePQ[i] = true;
				}
			}
		}
	}

156
157
	

Kirill Terekhov's avatar
Kirill Terekhov committed
158

159
160
	void MLMTILUC_preconditioner::DumpMatrix(const interval<INMOST_DATA_ENUM_TYPE, Interval> & Address,
											 const std::vector< std::vector<Sparse::Row::entry> >& Entries,
Kirill Terekhov's avatar
Kirill Terekhov committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
											 INMOST_DATA_ENUM_TYPE wmbeg, INMOST_DATA_ENUM_TYPE wmend,
											 std::string file_name)
	{
		INMOST_DATA_REAL_TYPE norm1 = 0, norm2 = 0, max = -1.0e54, min = 1.0e54, minabs = 1.0e54;
		INMOST_DATA_REAL_TYPE vrowmax, diag, mindiag = 1.0e54, maxdiag = -1.0e54, maxabsdiag = -1.0e54, minabsdiag = 1.0e54;
		INMOST_DATA_ENUM_TYPE nnz = 0, dominant_rows = 0, dominant_cols = 0, irowmax = 0, nodiag = 0;
		INMOST_DATA_ENUM_TYPE addrbeg = Address.get_interval_beg();
		INMOST_DATA_ENUM_TYPE addrend = Address.get_interval_end();
		interval<INMOST_DATA_ENUM_TYPE,INMOST_DATA_REAL_TYPE> vcolmax(wmbeg,wmend,0);
		interval<INMOST_DATA_ENUM_TYPE,INMOST_DATA_ENUM_TYPE> icolmax(wmbeg,wmend,ENUMUNDEF);
		for (INMOST_DATA_ENUM_TYPE k = wmbeg; k < wmend; ++k) 
		{
			if( k < addrbeg || k >= addrend) continue;
			nnz += Address[k].Size();
			vrowmax = 0;

			bool diag_found = false;
			diag = 0;
179
			int Athr = Address[k].thr;
180
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it)
Kirill Terekhov's avatar
Kirill Terekhov committed
181
			{
182
183
184
				norm1 += fabs(Entries[Athr][it].second);
				norm2 += Entries[Athr][it].second*Entries[Athr][it].second;
				if( fabs(Entries[Athr][it].second) > vrowmax )
Kirill Terekhov's avatar
Kirill Terekhov committed
185
				{
186
187
					vrowmax = fabs(Entries[Athr][it].second);
					irowmax = Entries[Athr][it].first;
Kirill Terekhov's avatar
Kirill Terekhov committed
188
189
				}

190
				if( fabs(Entries[Athr][it].second) > vcolmax[Entries[Athr][it].first] )
Kirill Terekhov's avatar
Kirill Terekhov committed
191
				{
192
193
					vcolmax[Entries[Athr][it].first] = fabs(Entries[Athr][it].second);
					icolmax[Entries[Athr][it].first] = k;
Kirill Terekhov's avatar
Kirill Terekhov committed
194
				}
195
196
197
				if( Entries[Athr][it].second > max ) max = Entries[Athr][it].second;
				if( Entries[Athr][it].second < min ) min = Entries[Athr][it].second;
				if( fabs(Entries[Athr][it].second) < fabs(minabs) ) minabs = Entries[Athr][it].second;
Kirill Terekhov's avatar
Kirill Terekhov committed
198

199
				if( Entries[Athr][it].first == k )
Kirill Terekhov's avatar
Kirill Terekhov committed
200
201
				{
					diag_found = true;
202
					diag = Entries[Athr][it].second;
Kirill Terekhov's avatar
Kirill Terekhov committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
				}
			}

			if( diag_found )
			{
				if( mindiag > diag ) mindiag = diag;
				if( maxdiag < diag ) maxdiag = diag;
				if( minabsdiag > fabs(diag) ) minabsdiag = fabs(diag);
				if( maxabsdiag < fabs(diag) ) maxabsdiag = fabs(diag);
			}
			else nodiag++;

			if( irowmax == k ) ++dominant_rows;
		}

		for (INMOST_DATA_ENUM_TYPE k = wmbeg; k < wmend; ++k) if( icolmax[k] == k ) ++dominant_cols;

		std::cout << "Writing matrix to " << file_name.c_str() << std::endl;
		std::fstream fout(file_name.c_str(),std::ios::out);
		fout << "%%MatrixMarket matrix coordinate real general" << std::endl;
		fout << "% maximum " << max << std::endl;
		fout << "% minimum " << min << std::endl;
		fout << "% absolute minimum " << minabs << std::endl;
		fout << "% A 1-norm  " << norm1 << std::endl;
		fout << "% A 2-norm  " << sqrt(norm2) << std::endl;
		fout << "% mean 1-norm  " << norm1/(wmend-wmbeg) << std::endl;
		fout << "% mean 2-norm  " << sqrt(norm2/(wmend-wmbeg)) << std::endl;
		fout << "% dominant rows  " << dominant_rows << std::endl;
		fout << "% dominant cols  " << dominant_cols << std::endl;
		fout << "% maximal diagonal value " << maxdiag << std::endl;
		fout << "% minimal diagonal value " << mindiag << std::endl;
		fout << "% absolute maximal diagonal value " << maxabsdiag << std::endl;
		fout << "% absolute minimal diagonal value " << minabsdiag << std::endl;
		fout << "% no diagonal value  " << nodiag << std::endl;
		fout << "% true matrix indices interval " << wmbeg << ":" << wmend << std::endl;
		fout << std::scientific;
		
240
241
		//fout.close(); return;
		
Kirill Terekhov's avatar
Kirill Terekhov committed
242
243
244
245
		fout << wmend-wmbeg << " " << wmend-wmbeg << " " << nnz << std::endl;;
		for (INMOST_DATA_ENUM_TYPE k = wmbeg; k < wmend; ++k)
		{
			if( k < addrbeg || k >= addrend) continue;
246
			int Athr = Address[k].thr;
247
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it)
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
				fout << (k-wmbeg+1) << " " << (Entries[Athr][it].first-wmbeg+1) << " " << Entries[Athr][it].second << std::endl;
		}
		fout.close();
	}
	INMOST_DATA_ENUM_TYPE MLMTILUC_preconditioner::ComputeNonzeroes(const Block& b, const interval<INMOST_DATA_ENUM_TYPE, Interval>& Address, const std::vector<std::vector<Sparse::Row::entry> >& Entries)
	{
		INMOST_DATA_ENUM_TYPE rbeg = b.row_start, rend = b.row_end;
		INMOST_DATA_ENUM_TYPE cbeg = b.col_start, cend = b.col_end;
		INMOST_DATA_ENUM_TYPE ret = 0;
		for (INMOST_DATA_ENUM_TYPE k = rbeg; k < rend; ++k)
		{
			int Athr = Address[k].thr;
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) if (cbeg <= Entries[Athr][it].first && Entries[Athr][it].first < cend)
				ret++;
		}
		return ret;
	}
	INMOST_DATA_ENUM_TYPE MLMTILUC_preconditioner::ComputeNonzeroes(const Block& b, const interval<INMOST_DATA_ENUM_TYPE, Interval>& Address, const std::vector< std::vector<Sparse::Row::entry> >& Entries, const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE>& localQ)
	{
		INMOST_DATA_ENUM_TYPE rbeg = b.row_start, rend = b.row_end;
		INMOST_DATA_ENUM_TYPE cbeg = b.col_start, cend = b.col_end;
		INMOST_DATA_ENUM_TYPE ret = 0;
		for (INMOST_DATA_ENUM_TYPE k = rbeg; k < rend; ++k)
		{
			int Athr = Address[k].thr;
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) if (cbeg <= localQ[Entries[Athr][it].first] && localQ[Entries[Athr][it].first] < cend)
				ret++;
		}
		return ret;
	}
	void MLMTILUC_preconditioner::DumpMatrixBlock(const Block & b, 
		const interval<INMOST_DATA_ENUM_TYPE, Interval>& Address,
		const std::vector< std::vector<Sparse::Row::entry> >& Entries,
		std::string file_name)
	{
		INMOST_DATA_ENUM_TYPE rbeg = b.row_start, rend = b.row_end;
		INMOST_DATA_ENUM_TYPE cbeg = b.col_start, cend = b.col_end;
		INMOST_DATA_REAL_TYPE norm1 = 0, norm2 = 0, max = -1.0e54, min = 1.0e54, minabs = 1.0e54;
		INMOST_DATA_REAL_TYPE vrowmax, diag, mindiag = 1.0e54, maxdiag = -1.0e54, maxabsdiag = -1.0e54, minabsdiag = 1.0e54;
		INMOST_DATA_ENUM_TYPE nnz = 0, dominant_rows = 0, dominant_cols = 0, irowmax = 0, nodiag = 0;
		INMOST_DATA_ENUM_TYPE addrbeg = Address.get_interval_beg();
		INMOST_DATA_ENUM_TYPE addrend = Address.get_interval_end();
		interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> vcolmax(cbeg, cend, 0);
		interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> icolmax(cbeg, cend, ENUMUNDEF);
		for (INMOST_DATA_ENUM_TYPE k = rbeg; k < rend; ++k)
		{
			if (k < addrbeg || k >= addrend) continue;
			vrowmax = 0;

			bool diag_found = false;
			diag = 0;
			int Athr = Address[k].thr;
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) if( cbeg <= Entries[Athr][it].first && Entries[Athr][it].first < cend )
			{
				nnz++;
				norm1 += fabs(Entries[Athr][it].second);
				norm2 += Entries[Athr][it].second * Entries[Athr][it].second;
				if (fabs(Entries[Athr][it].second) > vrowmax)
				{
					vrowmax = fabs(Entries[Athr][it].second);
					irowmax = Entries[Athr][it].first;
				}

				if (fabs(Entries[Athr][it].second) > vcolmax[Entries[Athr][it].first])
				{
					vcolmax[Entries[Athr][it].first] = fabs(Entries[Athr][it].second);
					icolmax[Entries[Athr][it].first] = k;
				}
				if (Entries[Athr][it].second > max) max = Entries[Athr][it].second;
				if (Entries[Athr][it].second < min) min = Entries[Athr][it].second;
				if (fabs(Entries[Athr][it].second) < fabs(minabs)) minabs = Entries[Athr][it].second;

				if (Entries[Athr][it].first == k)
				{
					diag_found = true;
					diag = Entries[Athr][it].second;
				}
			}

			if (diag_found)
			{
				if (mindiag > diag) mindiag = diag;
				if (maxdiag < diag) maxdiag = diag;
				if (minabsdiag > fabs(diag)) minabsdiag = fabs(diag);
				if (maxabsdiag < fabs(diag)) maxabsdiag = fabs(diag);
			}
			else nodiag++;

			if (irowmax == k) ++dominant_rows;
		}

		for (INMOST_DATA_ENUM_TYPE k = cbeg; k < cend; ++k) if (icolmax[k] == k) ++dominant_cols;

		std::cout << "Writing matrix to " << file_name.c_str() << std::endl;
		std::fstream fout(file_name.c_str(), std::ios::out);
		fout << "%%MatrixMarket matrix coordinate real general" << std::endl;
		fout << "% maximum " << max << std::endl;
		fout << "% minimum " << min << std::endl;
		fout << "% absolute minimum " << minabs << std::endl;
		fout << "% A 1-norm  " << norm1 << std::endl;
		fout << "% A 2-norm  " << sqrt(norm2) << std::endl;
		fout << "% mean 1-norm  " << norm1 / (rend - rbeg) << std::endl;
		fout << "% mean 2-norm  " << sqrt(norm2 / (rend - rbeg)) << std::endl;
		fout << "% dominant rows  " << dominant_rows << std::endl;
		fout << "% dominant cols  " << dominant_cols << std::endl;
		fout << "% maximal diagonal value " << maxdiag << std::endl;
		fout << "% minimal diagonal value " << mindiag << std::endl;
		fout << "% absolute maximal diagonal value " << maxabsdiag << std::endl;
		fout << "% absolute minimal diagonal value " << minabsdiag << std::endl;
		fout << "% no diagonal value  " << nodiag << std::endl;
		fout << "% true matrix row indices interval " << rbeg << ":" << rend << std::endl;
		fout << "% true matrix col indices interval " << cbeg << ":" << cend << std::endl;
		fout << std::scientific;

		//fout.close(); return;

		fout << rend - rbeg << " " << cend - cbeg << " " << nnz << std::endl;;
		for (INMOST_DATA_ENUM_TYPE k = rbeg; k < rend; ++k)
		{
			if (k < addrbeg || k >= addrend) continue;
			int Athr = Address[k].thr;
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) if (cbeg <= Entries[Athr][it].first && Entries[Athr][it].first < cend)
				fout << (k - rbeg + 1) << " " << (Entries[Athr][it].first - cbeg + 1) << " " << Entries[Athr][it].second << std::endl;
		}
		fout.close();
	}
	void MLMTILUC_preconditioner::DumpMatrixBlock(const Block& b, 
		const interval<INMOST_DATA_ENUM_TYPE, Interval>& Address,
		const std::vector<std::vector<Sparse::Row::entry> >& Entries,
		const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE>& localQ,
		std::string file_name)
	{
		INMOST_DATA_ENUM_TYPE rbeg = b.row_start, rend = b.row_end;
		INMOST_DATA_ENUM_TYPE cbeg = b.col_start, cend = b.col_end;
		INMOST_DATA_REAL_TYPE norm1 = 0, norm2 = 0, max = -1.0e54, min = 1.0e54, minabs = 1.0e54;
		INMOST_DATA_REAL_TYPE vrowmax, diag, mindiag = 1.0e54, maxdiag = -1.0e54, maxabsdiag = -1.0e54, minabsdiag = 1.0e54;
		INMOST_DATA_ENUM_TYPE nnz = 0, dominant_rows = 0, dominant_cols = 0, irowmax = 0, nodiag = 0;
		INMOST_DATA_ENUM_TYPE addrbeg = Address.get_interval_beg();
		INMOST_DATA_ENUM_TYPE addrend = Address.get_interval_end();
		interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> vcolmax(cbeg, cend, 0);
		interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> icolmax(cbeg, cend, ENUMUNDEF);
		for (INMOST_DATA_ENUM_TYPE k = rbeg; k < rend; ++k)
		{
			if (k < addrbeg || k >= addrend) continue;
			vrowmax = 0;

			bool diag_found = false;
			diag = 0;
			int Athr = Address[k].thr;
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) if (cbeg <= localQ[Entries[Athr][it].first] && localQ[Entries[Athr][it].first] < cend)
			{
				nnz++;
				norm1 += fabs(Entries[Athr][it].second);
				norm2 += Entries[Athr][it].second * Entries[Athr][it].second;
				if (fabs(Entries[Athr][it].second) > vrowmax)
				{
					vrowmax = fabs(Entries[Athr][it].second);
					irowmax = localQ[Entries[Athr][it].first];
				}

				if (fabs(Entries[Athr][it].second) > vcolmax[localQ[Entries[Athr][it].first]])
				{
					vcolmax[localQ[Entries[Athr][it].first]] = fabs(Entries[Athr][it].second);
					icolmax[localQ[Entries[Athr][it].first]] = k;
				}
				if (Entries[Athr][it].second > max) max = Entries[Athr][it].second;
				if (Entries[Athr][it].second < min) min = Entries[Athr][it].second;
				if (fabs(Entries[Athr][it].second) < fabs(minabs)) minabs = Entries[Athr][it].second;

				if (localQ[Entries[Athr][it].first] == k)
				{
					diag_found = true;
					diag = Entries[Athr][it].second;
				}
			}

			if (diag_found)
			{
				if (mindiag > diag) mindiag = diag;
				if (maxdiag < diag) maxdiag = diag;
				if (minabsdiag > fabs(diag)) minabsdiag = fabs(diag);
				if (maxabsdiag < fabs(diag)) maxabsdiag = fabs(diag);
			}
			else nodiag++;

			if (irowmax == k) ++dominant_rows;
		}

		for (INMOST_DATA_ENUM_TYPE k = cbeg; k < cend; ++k) if (icolmax[k] == k) ++dominant_cols;

		std::cout << "Writing matrix to " << file_name.c_str() << std::endl;
		std::fstream fout(file_name.c_str(), std::ios::out);
		fout << "%%MatrixMarket matrix coordinate real general" << std::endl;
		fout << "% maximum " << max << std::endl;
		fout << "% minimum " << min << std::endl;
		fout << "% absolute minimum " << minabs << std::endl;
		fout << "% A 1-norm  " << norm1 << std::endl;
		fout << "% A 2-norm  " << sqrt(norm2) << std::endl;
		fout << "% mean 1-norm  " << norm1 / (rend - rbeg) << std::endl;
		fout << "% mean 2-norm  " << sqrt(norm2 / (rend - rbeg)) << std::endl;
		fout << "% dominant rows  " << dominant_rows << std::endl;
		fout << "% dominant cols  " << dominant_cols << std::endl;
		fout << "% maximal diagonal value " << maxdiag << std::endl;
		fout << "% minimal diagonal value " << mindiag << std::endl;
		fout << "% absolute maximal diagonal value " << maxabsdiag << std::endl;
		fout << "% absolute minimal diagonal value " << minabsdiag << std::endl;
		fout << "% no diagonal value  " << nodiag << std::endl;
		fout << "% true matrix row indices interval " << rbeg << ":" << rend << std::endl;
		fout << "% true matrix col indices interval " << cbeg << ":" << cend << std::endl;
		fout << std::scientific;

		//fout.close(); return;

		fout << rend - rbeg << " " << cend - cbeg << " " << nnz << std::endl;;
		for (INMOST_DATA_ENUM_TYPE k = rbeg; k < rend; ++k)
		{
			if (k < addrbeg || k >= addrend) continue;
			int Athr = Address[k].thr;
466
467
468
469
470
471
472
473
474
475
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) //if (cbeg <= localQ[Entries[Athr][it].first] && localQ[Entries[Athr][it].first] < cend)
			{
				fout << (k - rbeg + 1);
				fout << " original " << Entries[Athr][it].first;
				fout << " new " << (localQ[Entries[Athr][it].first] - cbeg + 1);
				fout << " " << Entries[Athr][it].second;
				if (localQ[Entries[Athr][it].first] - cbeg == k - rbeg)
					fout << " diag ";
				fout << std::endl;
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
476
477
478
		}
		fout.close();
	}
479
480
	void MLMTILUC_preconditioner::CheckOrder(const interval<INMOST_DATA_ENUM_TYPE, Interval> & Address,
											 const std::vector< std::vector<Sparse::Row::entry> > & Entries,
Kirill Terekhov's avatar
Kirill Terekhov committed
481
482
483
											 INMOST_DATA_ENUM_TYPE rbeg, INMOST_DATA_ENUM_TYPE rend)
	{
		INMOST_DATA_ENUM_TYPE i,r;
484
		for (i = rbeg; i < rend; i++) if( Address[i].first < Address[i].last )
Kirill Terekhov's avatar
Kirill Terekhov committed
485
486
487
488
489
		{
			//check ordered on entry
			bool ordered = true;
			for (r = Address[i].first; r < Address[i].last-1; r++)
			{
490
				if( !(Entries[Address[i].thr][r].first < Entries[Address[i].thr][r+1].first) )
Kirill Terekhov's avatar
Kirill Terekhov committed
491
492
493
494
495
496
497
498
499
500
501
				{
					ordered = false;
					break;
				}
			}
			if( !ordered )
			{
				std::cout << "Row " << i << " not ordered: " << std::endl;
				std::cout << "Interval: " << Address[i].first << ":" << Address[i].last << std::endl;
				for (r = Address[i].first; r < Address[i].last; r++)
				{
502
					std::cout << "(" << Entries[Address[i].thr][r].first << "," << Entries[Address[i].thr][r].second << ") ";
Kirill Terekhov's avatar
Kirill Terekhov committed
503
504
505
506
507
508
509
				}
				std::cout << std::endl;
				throw -1;
			}
			bool nan = false;
			for (r = Address[i].first; r < Address[i].last; r++)
			{
510
				if( Entries[Address[i].thr][r].second != Entries[Address[i].thr][r].second )
Kirill Terekhov's avatar
Kirill Terekhov committed
511
512
513
514
515
516
517
518
519
520
521
				{
					nan = true;
					break;
				}
			}
			if( nan )
			{
				std::cout << "Row " << i << " contains nan: " << std::endl;
				std::cout << "Interval: " << Address[i].first << ":" << Address[i].last << std::endl;
				for (r = Address[i].first; r < Address[i].last; r++)
				{
522
					std::cout << "(" << Entries[Address[i].thr][r].first << "," << Entries[Address[i].thr][r].second << ") ";
Kirill Terekhov's avatar
Kirill Terekhov committed
523
524
525
526
527
528
529
530
531
				}
				std::cout << std::endl;
				throw -1;
			}
		}
	}
	
	void MLMTILUC_preconditioner::inversePQ(INMOST_DATA_ENUM_TYPE wbeg,
											INMOST_DATA_ENUM_TYPE wend,
532
533
											const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localP,
											const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localQ,
Kirill Terekhov's avatar
Kirill Terekhov committed
534
535
536
537
538
											interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & invP,
											interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & invQ)
	{
		//inverse reordering
		// in invPQ numbers indicate where to get current column
539
540
541
542
543
544
545
546
547
548
549
550
		for (INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k) invP[k] = ENUMUNDEF;
		for (INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k)
		{
			assert(invP[localP[k]] == ENUMUNDEF);
			invP[localP[k]] = k;
		}
		for (INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k) invQ[k] = ENUMUNDEF;
		for (INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k)
		{
			assert(invQ[localQ[k]] == ENUMUNDEF);
			invQ[localQ[k]] = k;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
551
552
553
554
555
	}
	void MLMTILUC_preconditioner::applyPQ(INMOST_DATA_ENUM_TYPE wbeg,
										  INMOST_DATA_ENUM_TYPE wend,
										  interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localP,
										  interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localQ,
556
557
										  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & invP,
										  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & invQ)
Kirill Terekhov's avatar
Kirill Terekhov committed
558
559
560
	{
		INMOST_DATA_ENUM_TYPE k;
		// compute reordering in global P,Q, we need it to compute reordering in vector during solve phase
561
		for (k = wbeg; k < wend; ++k)
Kirill Terekhov's avatar
Kirill Terekhov committed
562
563
564
565
566
		{
			localP[k] = ddP[invP[k]];
			localQ[k] = ddQ[invQ[k]];
		}
		// update reordering in global P,Q
567
		for (k = wbeg; k < wend; ++k)
Kirill Terekhov's avatar
Kirill Terekhov committed
568
569
570
571
572
		{
			ddP[k] = localP[k];
			ddQ[k] = localQ[k];
		}
	}
573
	INMOST_DATA_REAL_TYPE MLMTILUC_preconditioner::AddListOrdered(INMOST_DATA_ENUM_TYPE cbeg, 
574
575
																  const Interval & Address,
																  const std::vector<Sparse::Row::entry> & Entries,
576
577
578
579
																  INMOST_DATA_REAL_TYPE coef,
																  interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
																  interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValues,
																  INMOST_DATA_REAL_TYPE droptol)
Kirill Terekhov's avatar
Kirill Terekhov committed
580
	{
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
		INMOST_DATA_ENUM_TYPE curr = cbeg, next;
		INMOST_DATA_REAL_TYPE drop_sum = 0;
		for (INMOST_DATA_ENUM_TYPE it = Address.first; it < Address.last; ++it)
		{
			//~ assert(!Pivot[i]); // pivoted rows should be empty
			//~ assert(j >= k); // all indices are supposed to be to the right
			INMOST_DATA_ENUM_TYPE j = Entries[it].first;
			INMOST_DATA_REAL_TYPE u = coef*Entries[it].second;
			//eliminate values
			if (LineIndeces[j] != UNDEF) //there is an entry in the list
				LineValues[j] += u;
			else if( fabs(u) > droptol )
			{
				next = curr;
				while (next < j)
				{
					curr = next;
					next = LineIndeces[curr];
				}
				assert(curr < j);
				assert(j < next);
				LineIndeces[curr] = j;
				LineIndeces[j] = next;
				LineValues[j] = u; 
			}
			else drop_sum += u;
		}
608
		return drop_sum;
Kirill Terekhov's avatar
Kirill Terekhov committed
609
	}
610
	INMOST_DATA_REAL_TYPE MLMTILUC_preconditioner::AddListUnordered(INMOST_DATA_ENUM_TYPE & Sbeg,
611
612
																	const Interval & Address,
																	const std::vector<Sparse::Row::entry> & Entries,
613
614
615
616
																	INMOST_DATA_REAL_TYPE coef,
																	interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
																	interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValues,
																	INMOST_DATA_REAL_TYPE droptol)
Kirill Terekhov's avatar
Kirill Terekhov committed
617
	{
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
		INMOST_DATA_REAL_TYPE drop_sum = 0;
		for (INMOST_DATA_ENUM_TYPE it = Address.first; it < Address.last; ++it)
		{
			//~ assert(!Pivot[i]); // pivoted rows should be empty
			//~ assert(j >= k); // all indices are supposed to be to the right
			INMOST_DATA_ENUM_TYPE j = Entries[it].first;
			INMOST_DATA_REAL_TYPE u = coef*Entries[it].second;
			//eliminate values
			if (LineIndeces[j] != UNDEF) //there is an entry in the list
				LineValues[j] += u;
			else if( fabs(u) > droptol )
			{
				LineValues[j] = u;
				LineIndeces[j] = Sbeg;
				Sbeg = j;
			}
			else drop_sum += u;
		}
		return drop_sum;
Kirill Terekhov's avatar
Kirill Terekhov committed
637
	}
638
639
640
	void MLMTILUC_preconditioner::OrderList(INMOST_DATA_ENUM_TYPE & Sbeg,
											interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
											std::vector<INMOST_DATA_ENUM_TYPE> & indices)
Kirill Terekhov's avatar
Kirill Terekhov committed
641
	{
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
		indices.clear();
		INMOST_DATA_ENUM_TYPE i = Sbeg;
		while(i != EOL)
		{
			indices.push_back(i);
			i = LineIndeces[i];
		}
		if( !indices.empty() )
		{
			std::sort(indices.begin(),indices.end());
			Sbeg = indices[0];
			for(size_t qt = 1; qt < indices.size(); ++qt)
				LineIndeces[indices[qt-1]] = indices[qt];
			LineIndeces[indices.back()] = EOL;
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
657
	}
658
659
660
661
662
663
664
665
666
667
668
669
670
671
	
	void MLMTILUC_preconditioner::ScaleList(INMOST_DATA_REAL_TYPE coef,
											INMOST_DATA_ENUM_TYPE beg,
											interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
											interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValues)
	{										
		INMOST_DATA_ENUM_TYPE i = beg;
		while (i != EOL)
		{
			LineValues[i] *= coef;
			i = LineIndeces[i];
		}
	}
	INMOST_DATA_REAL_TYPE MLMTILUC_preconditioner::Estimator1(INMOST_DATA_ENUM_TYPE k,
672
673
674
															  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
															  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValues,
															  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & Est,
675
															  INMOST_DATA_REAL_TYPE & mu_update)
Kirill Terekhov's avatar
Kirill Terekhov committed
676
	{
677
678
		INMOST_DATA_REAL_TYPE mup = - Est[k] + 1.0;
		INMOST_DATA_REAL_TYPE mum = - Est[k] - 1.0;
679
680
681
682
		INMOST_DATA_REAL_TYPE smup = 0, smum = 0;
		INMOST_DATA_ENUM_TYPE i = LineIndeces[k];
		while (i != EOL)
		{
683
684
685
686
687
			if (i > k)
			{
				smup += fabs(Est[i] + LineValues[i] * mup);
				smum += fabs(Est[i] + LineValues[i] * mum);
			}
688
689
			i = LineIndeces[i];
		}
690
691
692
693
		if (fabs(mup) + smup > fabs(mum) + smum) 
			mu_update = mup; 
		else 
			mu_update = mum;
694
		return std::max(fabs(mup),fabs(mum));
Kirill Terekhov's avatar
Kirill Terekhov committed
695
	}
696
697
698
	
	
	INMOST_DATA_REAL_TYPE MLMTILUC_preconditioner::Estimator2(INMOST_DATA_ENUM_TYPE k,
699
700
701
															  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
															  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValues,
															  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & Est,
702
															  INMOST_DATA_REAL_TYPE & mu_update)
Kirill Terekhov's avatar
Kirill Terekhov committed
703
	{
704
705
		INMOST_DATA_REAL_TYPE mup = - Est[k] + 1.0;
		INMOST_DATA_REAL_TYPE mum = - Est[k] - 1.0;
706
707
708
709
710
		INMOST_DATA_ENUM_TYPE np = 0, nm = 0;
		//start from the element next after diagonal position
		INMOST_DATA_ENUM_TYPE i = LineIndeces[k];
		while (i != EOL)
		{
711
712
713
			INMOST_DATA_REAL_TYPE v = Est[i];
			INMOST_DATA_REAL_TYPE vp = fabs(v + LineValues[i] * mup);
			INMOST_DATA_REAL_TYPE vm = fabs(v + LineValues[i] * mum);
714
			v = fabs(v);
715
716
717
718
			if (vp > std::max<INMOST_DATA_REAL_TYPE>(2 * v, 0.5)) np++;
			if (vm > std::max<INMOST_DATA_REAL_TYPE>(2 * v, 0.5)) nm++;
			if (std::max<INMOST_DATA_REAL_TYPE>(2 * vp, 0.5) < v) np--;
			if (std::max<INMOST_DATA_REAL_TYPE>(2 * vm, 0.5) < v) nm--;
719
720
			i = LineIndeces[i];
		}
721
722
723
724
		if (fabs(mup) + np > fabs(mum)+nm) 
			mu_update = mup; 
		else 
			mu_update = mum;
725
		return std::max(fabs(mup), fabs(mum));
Kirill Terekhov's avatar
Kirill Terekhov committed
726
	}
727
728
	
	void MLMTILUC_preconditioner::EstimatorUpdate(INMOST_DATA_ENUM_TYPE k,
729
730
												  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
												  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValues,
731
732
												  interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & Est,
												  INMOST_DATA_REAL_TYPE & mu_update)
Kirill Terekhov's avatar
Kirill Terekhov committed
733
	{
734
735
736
737
738
739
		INMOST_DATA_ENUM_TYPE i = LineIndeces[k];
		while (i != EOL)
		{
			Est[i] += LineValues[i] * mu_update;
			i = LineIndeces[i];
		}
Kirill Terekhov's avatar
Kirill Terekhov committed
740
	}
741
742
743
	
	void MLMTILUC_preconditioner::DiagonalUpdate(INMOST_DATA_ENUM_TYPE k,
												 interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & Diag,
744
745
746
747
												 const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndecesL,
												 const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValuesL,
												 const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndecesU,
												 const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValuesU)
Kirill Terekhov's avatar
Kirill Terekhov committed
748
	{
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
		INMOST_DATA_ENUM_TYPE Li = LineIndecesL[k];
		INMOST_DATA_ENUM_TYPE Ui = LineIndecesU[k];
		while (Li != EOL && Ui != EOL)
		{
			if( Ui > Li ) Li = LineIndecesL[Li];
			else if( Li > Ui ) Ui = LineIndecesU[Ui];
			else
			{
				assert(Ui > k && Li > k && Ui == Li);
				//~ std::cout << "Diag[" << Ui << "] " << Diag[Ui] << " - " << LineValuesL[Li]*LineValuesU[Ui]*Diag[k] << " = ";
				Diag[Ui] -= LineValuesL[Li]*LineValuesU[Ui]*Diag[k];
				//~ std::cout << Diag[Ui] << " from " << Li << "," << Ui << std::endl;
				Li = LineIndecesL[Li];
				Ui = LineIndecesU[Ui];
			}
		}
	}
	
	void MLMTILUC_preconditioner::ClearList(INMOST_DATA_ENUM_TYPE beg,
											interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & LineIndeces,
											interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_REAL_TYPE> & LineValues)
	{
		INMOST_DATA_ENUM_TYPE i = beg, j;
		while (i != EOL)
		{
			j = LineIndeces[i];
			LineValues[i] = 0.0; //clean values after use
			LineIndeces[i] = UNDEF; //clean indeces after use
			i = j;
		}
	}
	
	void MLMTILUC_preconditioner::PrepareTranspose(INMOST_DATA_ENUM_TYPE cbeg,
												   INMOST_DATA_ENUM_TYPE cend,
783
784
												   const interval<INMOST_DATA_ENUM_TYPE, Interval> & Address,
												   const std::vector< std::vector<Sparse::Row::entry> > & Entries,
785
786
787
												   interval<INMOST_DATA_ENUM_TYPE, Interval> G_Address,
												   std::vector< std::vector< std::pair<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> > > G_Entries)
												   //interval<INMOST_DATA_ENUM_TYPE, std::vector< std::pair<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> > > & Indices )
788
	{
789
790
791
#if defined(USE_OMP_FACT)
#pragma omp parallel
#endif
792
		{
793
			int thr = Thread();
794
			INMOST_DATA_ENUM_TYPE tseg = (cend - cbeg) / Threads();
795
			INMOST_DATA_ENUM_TYPE tbeg = cbeg + tseg * thr;
796
			INMOST_DATA_ENUM_TYPE tend = tbeg + tseg;
797
			if (thr == Threads() - 1) tend = cend;
798
			if (tend > tbeg)
799
			{
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
				for (INMOST_DATA_ENUM_TYPE k = tbeg; k < tend; ++k)
				{
					G_Address[k].thr = thr;
					G_Address[k].first = G_Address[k].last = 0;
				}
				for (INMOST_DATA_ENUM_TYPE i = cbeg; i < cend; ++i) //row-index
				{
					for (INMOST_DATA_ENUM_TYPE jt = Address[i].first; jt < Address[i].last; ++jt) //entry index
					{
						INMOST_DATA_ENUM_TYPE j = Entries[Address[i].thr][jt].first;
						if (tbeg <= j && j < tend)
							G_Address[j].last++;
					}
				}
				//Establish the addresses
				INMOST_DATA_ENUM_TYPE offset = 0;
				for (INMOST_DATA_ENUM_TYPE k = tbeg; k < tend; ++k)
				{
					G_Address[k].first += offset;
					G_Address[k].last += offset;
					offset += G_Address[k].Size();
				}
				//Allocate size for F storage
				G_Entries[thr].resize(G_Address[tend - 1].last);
				//Reset addresses to advance current fill position
				for (INMOST_DATA_ENUM_TYPE k = tbeg; k < tend; ++k)
					G_Address[k].last = G_Address[k].first;
				//Fill data for each thread
828
829
				for (INMOST_DATA_ENUM_TYPE i = cbeg; i < cend; ++i) //row-index
				{
830
831
832
833
834
835
836
					for (INMOST_DATA_ENUM_TYPE jt = Address[i].first; jt < Address[i].last; ++jt) //entry index
					{
						INMOST_DATA_ENUM_TYPE j = Entries[Address[i].thr][jt].first;
						if (tbeg <= j && j < tend)
							G_Entries[thr][G_Address[j].last++] = std::make_pair(i, jt);
							//Indices[j].push_back(std::make_pair(i, jt)); // Entries[j].first is column index, record row-index, entry index
					}
837
				}
838
			}
839
840
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
841

842
843
844
	void MLMTILUC_preconditioner::PrepareGraph(INMOST_DATA_ENUM_TYPE wbeg,
					  						   INMOST_DATA_ENUM_TYPE wend,
					  						   const interval<INMOST_DATA_ENUM_TYPE, Interval> & Address,
845
					  						   const std::vector< std::vector<Sparse::Row::entry> >& Entries,
846
847
848
											   interval<INMOST_DATA_ENUM_TYPE, Interval>& G_Address,
											   std::vector< std::vector<INMOST_DATA_ENUM_TYPE> >& G_Entries)
					  						   //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & G)
849
	{
850
851
852
853
#if defined(USE_OMP_FACT)
#pragma omp parallel for
#endif
		for(INMOST_DATA_INTEGER_TYPE k = wbeg; k < static_cast<INMOST_DATA_INTEGER_TYPE>(wend); ++k)
854
		{
855
856
857
			//G[k].reserve(Address[k].Size());
			G_Address[k].thr = Thread();
			G_Address[k].first = G_Entries[G_Address[k].thr].size();
858
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) //if( !check_zero(Entries[it].second) )
859
860
861
				G_Entries[G_Address[k].thr].push_back(Entries[Address[k].thr][it].first);
				//G[k].push_back(Entries[Address[k].thr][it].first);
			G_Address[k].last = G_Entries[G_Address[k].thr].size();
862
863
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
864

865
866
	void MLMTILUC_preconditioner::PrepareGraphTranspose(INMOST_DATA_ENUM_TYPE wbeg,
							   							INMOST_DATA_ENUM_TYPE wend,
867
868
869
870
871
872
														const interval<INMOST_DATA_ENUM_TYPE, Interval>& G_Address,
														const std::vector< std::vector<INMOST_DATA_ENUM_TYPE> >& G_Entries,
														interval<INMOST_DATA_ENUM_TYPE, Interval>& tG_Address,
														std::vector< std::vector<INMOST_DATA_ENUM_TYPE> >& tG_Entries)
							   							//const interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & G,
							   							//interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & tG)
873
874
	{
		//preallocate tG???
875
876
877
#if defined(USE_OMP_FACT)
#pragma omp parallel
#endif
878
		{
879
880
881
			int thr = Thread();
			INMOST_DATA_ENUM_TYPE cbeg = tG_Address.get_interval_beg();
			INMOST_DATA_ENUM_TYPE cend = tG_Address.get_interval_end();
882
			INMOST_DATA_ENUM_TYPE tseg = (cend - cbeg) / Threads();
883
			INMOST_DATA_ENUM_TYPE tbeg = cbeg + tseg * thr;
884
			INMOST_DATA_ENUM_TYPE tend = tbeg + tseg;
885
			if (thr == Threads() - 1) tend = cend;
886
			if (tend > tbeg)
887
			{
888
889
				for (INMOST_DATA_ENUM_TYPE k = tbeg; k < tend; ++k)
				{
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
					tG_Address[k].thr = thr;
					tG_Address[k].first = tG_Address[k].last = 0;
				}
				for (INMOST_DATA_ENUM_TYPE i = wbeg; i < wend; ++i) //row-index
				{
					for (INMOST_DATA_ENUM_TYPE jt = G_Address[i].first; jt < G_Address[i].last; ++jt) //entry index
					{
						INMOST_DATA_ENUM_TYPE j = G_Entries[G_Address[i].thr][jt];
						if (tbeg <= j && j < tend)
							tG_Address[j].last++;
					}
				}
				//Establish the addresses
				INMOST_DATA_ENUM_TYPE offset = 0;
				for (INMOST_DATA_ENUM_TYPE k = tbeg; k < tend; ++k)
				{
					tG_Address[k].first += offset;
					tG_Address[k].last += offset;
					offset += tG_Address[k].Size();
				}
				//Allocate size for F storage
				tG_Entries[thr].resize(tG_Address[tend - 1].last);
				//Reset addresses to advance current fill position
				for (INMOST_DATA_ENUM_TYPE k = tbeg; k < tend; ++k)
					tG_Address[k].last = tG_Address[k].first;
				//Fill data for each thread
				for (INMOST_DATA_ENUM_TYPE i = wbeg; i < wend; ++i) //row-index
				{
					for (INMOST_DATA_ENUM_TYPE jt = G_Address[i].first; jt < G_Address[i].last; ++jt) //entry index
					{
						INMOST_DATA_ENUM_TYPE j = G_Entries[G_Address[i].thr][jt];
						if (tbeg <= j && j < tend)
							tG_Entries[thr][tG_Address[j].last++] = i;
					}
924
				}
925
			}
926
927
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
928

929
930
	void MLMTILUC_preconditioner::PrepareGraphProduct(INMOST_DATA_ENUM_TYPE wbeg,
													  INMOST_DATA_ENUM_TYPE wend,
931
932
933
934
935
936
937
938
939
													  const interval<INMOST_DATA_ENUM_TYPE, Interval>& G_Address,
													  const std::vector< std::vector<INMOST_DATA_ENUM_TYPE> >& G_Entries,
													  const interval<INMOST_DATA_ENUM_TYPE, Interval>& tG_Address,
													  const std::vector< std::vector<INMOST_DATA_ENUM_TYPE> >& tG_Entries,
													  interval<INMOST_DATA_ENUM_TYPE, Interval>& pG_Address,
													  std::vector< std::vector<INMOST_DATA_ENUM_TYPE> >& pG_Entries)
							 						  //const interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & G,
							 						  //const interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & tG,
							 						  //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & pG)
940
941
942
	{
#if defined(USE_OMP_FACT)
#pragma omp parallel
Kirill Terekhov's avatar
Kirill Terekhov committed
943
#endif
944
945
946
947
		{
			interval< INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE > List(wbeg,wend,ENUMUNDEF);
#if defined(USE_OMP_FACT)
#pragma omp for
Kirill Terekhov's avatar
Kirill Terekhov committed
948
#endif
949
			for(INMOST_DATA_INTEGER_TYPE k = wbeg; k < static_cast<INMOST_DATA_INTEGER_TYPE>(wend); ++k)
950
951
952
			{
				INMOST_DATA_ENUM_TYPE Beg = EOL, nnz = 0;
				// go over connection of k-th row
953
954
				List[k] = Beg;
				Beg = k;
955
956
				//for(INMOST_DATA_ENUM_TYPE it = 0; it < G[k].size(); ++it)
				for (INMOST_DATA_ENUM_TYPE it = G_Address[k].first; it < G_Address[k].last; ++it)
957
				{
958
959
960
961
					//INMOST_DATA_ENUM_TYPE kt = G[k][it];
					INMOST_DATA_ENUM_TYPE kt = G_Entries[G_Address[k].thr][it];
					//for(INMOST_DATA_ENUM_TYPE jt = 0; jt < tG[kt].size(); ++jt)
					for (INMOST_DATA_ENUM_TYPE jt = tG_Address[kt].first; jt < tG_Address[kt].last; ++jt)
962
					{
963
964
						//INMOST_DATA_ENUM_TYPE lt = tG[kt][jt];
						INMOST_DATA_ENUM_TYPE lt = tG_Entries[tG_Address[kt].thr][jt];
965
						//insert to linked list
966
967
968
969
970
971
						if (List[lt] == ENUMUNDEF)
						{
							List[lt] = Beg;
							Beg = lt;
							nnz++;
						}
972
973
974
					}
				}
				// wadj_sep[k-wbeg] = nnz;
975
976
977
978
				int thr = Thread();
				pG_Address[k].thr = thr;
				pG_Address[k].first = pG_Entries[thr].size();
				//pG[k].reserve(nnz);
979
				INMOST_DATA_ENUM_TYPE it = Beg, jt;
980
				while( it != static_cast<INMOST_DATA_ENUM_TYPE>(k) )
981
				{
982
983
					//pG[k].push_back(it);
					pG_Entries[thr].push_back(it);
984
985
986
987
988
					jt = List[it]; //save next entry
					List[it] = ENUMUNDEF; //clear list
					it = jt; //restore next
				}
				List[k] = ENUMUNDEF;
989
				pG_Address[k].last = pG_Entries[thr].size();
990
991
992
			}
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
993

994
995
996
997
998
999
	int MLMTILUC_preconditioner::Thread()
	{
#if defined(USE_OMP)
		return omp_get_thread_num();
#else
		return 0;
Kirill Terekhov's avatar
Kirill Terekhov committed
1000
#endif
1001
1002
1003
1004
1005
1006
1007
1008
	}

	int MLMTILUC_preconditioner::Threads()
	{
#if defined(USE_OMP)
		return omp_get_max_threads();
#else
		return 1;
Kirill Terekhov's avatar
Kirill Terekhov committed
1009
#endif
1010
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1011

1012
1013
1014
	void MLMTILUC_preconditioner::ColumnInterval(INMOST_DATA_ENUM_TYPE wbeg, 
						 						 INMOST_DATA_ENUM_TYPE wend,
						 						 const interval<INMOST_DATA_ENUM_TYPE, Interval> & Address,
1015
						 						 const std::vector< std::vector<Sparse::Row::entry> > & Entries,
1016
1017
1018
1019
1020
						 						 INMOST_DATA_ENUM_TYPE & cbeg,
						 						 INMOST_DATA_ENUM_TYPE & cend)
	{
		cbeg = ENUMUNDEF, cend = 0;
		for(INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k) 
Kirill Terekhov's avatar
Kirill Terekhov committed
1021
		{
1022
			int Athr = Address[k].thr;
1023
1024
			for (INMOST_DATA_ENUM_TYPE it = Address[k].first; it < Address[k].last; ++it) 
			{
1025
				INMOST_DATA_ENUM_TYPE jt = Entries[Athr][it].first;
1026
1027
1028
				if( jt > cend ) cend = jt;
				if( jt < cbeg ) cbeg = jt;
			}
Kirill Terekhov's avatar
Kirill Terekhov committed
1029
		}
1030
1031
		cend++;
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1032

1033
	void MLMTILUC_preconditioner::FilterGraph(const Block & b,
1034
1035
1036
1037
1038
1039
1040
1041
											  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & invP,
				 		  					  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localQ,
											  const interval<INMOST_DATA_ENUM_TYPE, Interval>& in_G_Address,
											  const std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > in_G_Entries,
											  interval<INMOST_DATA_ENUM_TYPE, Interval>& out_G_Address,
											  std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > out_G_Entries)
											  //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & G_in,
											  //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & G_out)
1042
1043
1044
	{
		INMOST_DATA_ENUM_TYPE wbeg = b.row_start, wend = b.row_end;
		INMOST_DATA_ENUM_TYPE cbeg = b.col_start, cend = b.col_end;
1045
1046
1047
1048
		out_G_Address.set_interval_beg(wbeg);
		out_G_Address.set_interval_end(wend);
		out_G_Entries.clear();
		out_G_Entries.resize(Threads());
1049
1050
1051
#if defined(USE_OMP)
#pragma omp parallel for
#endif
1052
		for(INMOST_DATA_INTEGER_TYPE k = wbeg; k < static_cast<INMOST_DATA_INTEGER_TYPE>(wend); ++k)
1053
		{
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
			int thr = Thread();
			out_G_Address[k].thr = thr;
			out_G_Address[k].first = out_G_Entries[thr].size();
			for (INMOST_DATA_ENUM_TYPE jt = in_G_Address[invP[k]].first; jt < in_G_Address[invP[k]].last; ++jt)
			{
				INMOST_DATA_ENUM_TYPE j = localQ[in_G_Entries[in_G_Address[invP[k]].thr][jt]];
				if (cbeg <= j && j < cend)
					out_G_Entries[thr].push_back(j);
			}
			out_G_Address[k].last = out_G_Entries[thr].size();
			/*
1065
1066
1067
1068
1069
1070
1071
1072
			G_out[k] = G_in[invP[k]];
			INMOST_DATA_ENUM_TYPE it = 0, jt = 0;
			while(it < G_out[k].size())
			{
				G_out[k][jt] = localQ[G_out[k][it++]]; //localQ is the new column position
				if( cbeg <= G_out[k][jt] && G_out[k][jt] < cend ) jt++; //column is inside block
			}
			G_out[k].resize(jt);
1073
			*/
1074
1075
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1076

1077
	void MLMTILUC_preconditioner::FilterGraphTranspose(const Block & b,
1078
1079
1080
1081
1082
1083
1084
1085
											  		  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localP,
				 		  					  		  const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & invQ,
													  const interval<INMOST_DATA_ENUM_TYPE, Interval> & in_tG_Address,
													  const std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > in_tG_Entries,
													  interval<INMOST_DATA_ENUM_TYPE, Interval> & out_tG_Address,
													  std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > out_tG_Entries)
											  		  //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & tG_in,
											  		  //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & tG_out)
1086
1087
1088
	{
		INMOST_DATA_ENUM_TYPE wbeg = b.row_start, wend = b.row_end;
		INMOST_DATA_ENUM_TYPE cbeg = b.col_start, cend = b.col_end;
1089
1090
1091
1092
		out_tG_Address.set_interval_beg(cbeg);
		out_tG_Address.set_interval_end(cend);
		out_tG_Entries.clear();
		out_tG_Entries.resize(Threads());
1093
1094
#if defined(USE_OMP)
#pragma omp parallel for
Kirill Terekhov's avatar
Kirill Terekhov committed
1095
#endif
1096
		for(INMOST_DATA_INTEGER_TYPE k = cbeg; k < static_cast<INMOST_DATA_INTEGER_TYPE>(cend); ++k)
1097
		{
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
			int thr = Thread();
			out_tG_Address[k].thr = thr;
			out_tG_Address[k].first = out_tG_Entries[thr].size();
			for (INMOST_DATA_ENUM_TYPE jt = in_tG_Address[invQ[k]].first; jt < in_tG_Address[invQ[k]].last; ++jt)
			{
				INMOST_DATA_ENUM_TYPE j = localP[in_tG_Entries[in_tG_Address[invQ[k]].thr][jt]];
				if (wbeg <= j && j < wend)
					out_tG_Entries[thr].push_back(j);
			}
			out_tG_Address[k].last = out_tG_Entries[thr].size();
			/*
1109
1110
1111
1112
1113
1114
1115
1116
			tG_out[k] = tG_in[invQ[k]];
			INMOST_DATA_ENUM_TYPE it = 0, jt = 0;
			while(it < tG_out[k].size())
			{
				tG_out[k][jt] = localP[tG_out[k][it++]]; //localP is the new row position
				if( wbeg <= tG_out[k][jt] && tG_out[k][jt] < wend ) jt++; //row is inside block
			}
			tG_out[k].resize(jt);
1117
			*/
1118
1119
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1120

1121
	void MLMTILUC_preconditioner::FilterGraphProduct(const Block & b,
1122
1123
1124
1125
1126
1127
1128
1129
													 const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & invP,
				 		  							 const interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localP,
													 const interval<INMOST_DATA_ENUM_TYPE, Interval>& in_pG_Address,
													 const std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > in_pG_Entries,
													 interval<INMOST_DATA_ENUM_TYPE, Interval>& out_pG_Address,
													 std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > out_pG_Entries)
													 //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & pG_in,
													 //interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & pG_out)
1130
1131
	{
		INMOST_DATA_ENUM_TYPE wbeg = b.row_start, wend = b.row_end;
1132
1133
1134
1135
		out_pG_Address.set_interval_beg(wbeg);
		out_pG_Address.set_interval_end(wend);
		out_pG_Entries.clear();
		out_pG_Entries.resize(Threads());
1136
1137
#if defined(USE_OMP)
#pragma omp parallel for
1138
#endif	
1139
		for(INMOST_DATA_INTEGER_TYPE k = wbeg; k < static_cast<INMOST_DATA_INTEGER_TYPE>(wend); ++k)
1140
		{
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
			int thr = Thread();
			out_pG_Address[k].thr = thr;
			out_pG_Address[k].first = out_pG_Entries[thr].size();
			for (INMOST_DATA_ENUM_TYPE jt = in_pG_Address[invP[k]].first; jt < in_pG_Address[invP[k]].last; ++jt)
			{
				INMOST_DATA_ENUM_TYPE j = localP[in_pG_Entries[in_pG_Address[invP[k]].thr][jt]];
				if (wbeg <= j && j < wend)
					out_pG_Entries[thr].push_back(j);
			}
			out_pG_Address[k].last = out_pG_Entries[thr].size();
			/*
1152
1153
1154
1155
1156
1157
1158
1159
			pG_out[k] = pG_in[invP[k]];
			INMOST_DATA_ENUM_TYPE it = 0, jt = 0;
			while(it < pG_out[k].size())
			{
				pG_out[k][jt] = localP[pG_out[k][it++]]; //localP is the new row position
				if( wbeg <= pG_out[k][jt] && pG_out[k][jt] < wend ) jt++; //row is inside block
			}
			pG_out[k].resize(jt);
1160
			*/
1161
1162
		}
	}
Kirill Terekhov's avatar
Kirill Terekhov committed
1163

1164
1165
1166
1167
	void MLMTILUC_preconditioner::DumpGraph(std::string name, 
											const interval<INMOST_DATA_ENUM_TYPE, Interval>& G_Address,
											const std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > G_Entries)
											//interval< INMOST_DATA_ENUM_TYPE, std::vector<INMOST_DATA_ENUM_TYPE> > & G)
1168
1169
	{
		INMOST_DATA_ENUM_TYPE wbeg, wend, cbeg, cend, nnz = 0, side;
1170
1171
		wbeg = G_Address.get_interval_beg();
		wend = G_Address.get_interval_end();
1172
1173
1174
1175
1176
		cbeg = ENUMUNDEF;
		cend = 0;
		std::cout << __FUNCTION__ << " " << name << std::endl;
		std::cout << "wbeg " << wbeg << " wend " << wend << std::endl;
		for(INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k)
Kirill Terekhov's avatar
Kirill Terekhov committed
1177
		{
1178
			for(INMOST_DATA_ENUM_TYPE it = G_Address[k].first; it < G_Address[k].last; ++it)
1179
			{
1180
				INMOST_DATA_ENUM_TYPE jt = G_Entries[G_Address[k].thr][it];
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
				if( cbeg > jt ) cbeg = jt;
				if( cend < jt ) cend = jt;
				nnz++;
			}
		}
		std::cout << "cbeg " << cbeg << " cend " << cend << std::endl;
		side = std::max(wend-wbeg,cend-cbeg);
		std::ofstream file(name.c_str());
		file << "%%MatrixMarket matrix coordinate real general\n";
		file << "%graph only, values are units\n";
		file << "%writing as square graph, some rows/cols may be missing\n";
		file << side << " " << side << " " << nnz << std::endl;
		for(INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k)
		{
1195
			for(INMOST_DATA_ENUM_TYPE it = G_Address[k].first; it < G_Address[k].last; ++it)
1196
			{
1197
				INMOST_DATA_ENUM_TYPE jt = G_Entries[G_Address[k].thr][it];
1198
1199
1200
1201
1202
1203
1204
1205
1206
				file << k-wbeg+1 << " " << jt-cbeg+1 << " 1\n";
			}
		}
		file.close();
	}

	void MLMTILUC_preconditioner::NestedDissection(INMOST_DATA_ENUM_TYPE wbeg,
												   INMOST_DATA_ENUM_TYPE wend,
												   const interval<INMOST_DATA_ENUM_TYPE, Interval> & Address,
1207
						 						   const std::vector< std::vector<Sparse::Row::entry> > & Entries,
1208
1209
1210
1211
1212
1213
						 						   interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localP,
				 		 						   interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE> & localQ,
												   std::vector<Block> & blocks,
												   INMOST_DATA_ENUM_TYPE max_size)
	{
		const int kway_parts = 2;
1214
		double /*timer = Timer(),*/ total_time = Timer();
1215
1216
1217
		INMOST_DATA_ENUM_TYPE cbeg, cend, sep, blks;
		ColumnInterval(wbeg,wend,Address,Entries,cbeg,cend);

1218
1219
1220
1221
1222
1223
		interval< INMOST_DATA_ENUM_TYPE, Interval > G_Address(wbeg,wend), tG_Address(cbeg,cend), pG_Address(wbeg,wend);
		std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > G_Entries(Threads()), tG_Entries(Threads()), pG_Entries(Threads());
		interval< INMOST_DATA_ENUM_TYPE, Interval > G2_Address, tG2_Address, pG2_Address;
		std::vector< std::vector<INMOST_DATA_ENUM_TYPE> > G2_Entries(Threads()), tG2_Entries(Threads()), pG2_Entries(Threads());
		interval< INMOST_DATA_ENUM_TYPE, Interval > * rG_Address = &G_Address, * rtG_Address = &tG_Address, * rpG_Address = &pG_Address;
		std::vector< std::vector<INMOST_DATA_ENUM_TYPE> >* rG_Entries = &G_Entries, * rtG_Entries = &tG_Entries, * rpG_Entries = &pG_Entries;
1224
1225
1226
1227
1228
		interval<INMOST_DATA_ENUM_TYPE, INMOST_DATA_ENUM_TYPE>  P(wbeg,wend), Q(cbeg,cend), invP(wbeg,wend), invQ(cbeg,cend);
		std::vector<Block> blocks_new;

		// std::cout << __FUNCTION__ << " row " << wbeg << ":" << wend << " col " << cbeg << ":" << cend << std::endl;
		
1229
		//~ timer = Timer();
1230

1231
1232
		PrepareGraph(wbeg,wend,Address,Entries,G_Address,G_Entries);
		PrepareGraphTranspose(wbeg,wend,G_Address,G_Entries,tG_Address,tG_Entries);
1233
1234
1235
1236
1237
1238
1239

		for(INMOST_DATA_ENUM_TYPE k = wbeg; k < wend; ++k) localP[k] = invP[k] = k;
		for(INMOST_DATA_ENUM_TYPE k = cbeg; k < cend; ++k) localQ[k] = invQ[k] = k;
		
		// std::cout << "prepare tG time " << Timer() - timer << std::endl;
		// if( wgt_sep )
		{
1240
			//~ timer = Timer();
1241
			PrepareGraphProduct(wbeg,wend,G_Address,G_Entries,tG_Address,tG_Entries,pG_Address,pG_Entries);