File: mergesort_macros.m4

package info (click to toggle)
librsb 1.3.0.2%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,792 kB
  • sloc: ansic: 274,405; f90: 108,468; cpp: 16,934; sh: 6,761; makefile: 1,679; objc: 692; awk: 22; sed: 1
file content (594 lines) | stat: -rw-r--r-- 17,328 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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
240
241
242
243
244
245
246
247
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
dnl
dnl
dnl	RSB_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_NAME(TYPE,BLOCKORIENTED)
dnl	-------------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates function dispatcher function name.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_NAME',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
rsb__do_mergesort`_'blockoriented`'dnl
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_ARGS(TYPE,BLOCKORIENTED)
dnl	-------------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates function dispatcher function arguments.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_ARGS',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
dnl
(
	rsb_coo_idx_t *iarray,
	rsb_coo_idx_t *jarray,
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *biarray,
',`')dnl
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *bjarray,'
,`')dnl
	void *array,
	rsb_nnz_idx_t length, 
ifelse(blockoriented,`BCSR',`	rsb_coo_idx_t mb,
',`')dnl
ifelse(blockoriented,`BCSR',`	rsb_coo_idx_t kb,
',`')dnl
	rsb_coo_idx_t *iresult,
	rsb_coo_idx_t *jresult,
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *biresult,
',`')dnl
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *bjresult,
',`')dnl
	void *result,
	rsb_type_t type)dnl
dnl
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_PROTOTYPE(TYPE,BLOCKORIENTED)
dnl	------------------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates function dispatcher function prototype.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_PROTOTYPE',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
rsb_err_t RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_NAME(mtype,blockoriented)dnl
RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_ARGS(mtype,blockoriented)dnl
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER(TYPE,BLOCKORIENTED)
dnl	--------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates function dispatcher.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER',`dnl
dnl
pushdef(`types',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_DISPATCHER_PROTOTYPE(,blockoriented)
dnl
{
	/*!
	 * \ingroup gr_util
	 *	This function will sort the non zero elements of a sparse ifelse(blockoriented,`VBR',`blocked ')`'matrix.
	 *      It will read row and column indices arrays, the values array,
	 *	and will sort them in separate output arrays.
	 *
	 * 	\param length  the input  arrays length
	 * 	\param iarray  the input  row    indices array
	 * 	\param jarray  the input  column indices array
	 * 	\param array   the input  mtype array
	 * 	\param iresult the output row    indices array
	 * 	\param jresult the output column indices array
	 * 	\param result  the output values array
ifelse(blockoriented,`CSR',`dnl
	 *	FIXME : UNDOCUMENTED
')dnl
ifelse(blockoriented,`VBR',`dnl
	 * 	\param biarray  the input  block row    indices array
	 * 	\param bjarray  the input  block column indices array
	 * 	\param biresult the output block row    indices array
	 * 	\param bjresult the output block column indices array
')dnl
ifelse(blockoriented,`BCSR',`
	 *	FIXME : UNDOCUMENTED
',`')dnl
	 *	Will sort  thethree arrays (iarray, jarray, array) following the 
	 *	criteria :
	 *
	 * 	(ia1,ja1)<=(ia2,ja2) iff (ia1<ia2) or ( (ia1==ia2) and (ja1<ja2) )
	 * 	i.e.: C (row major) ordering
	 */


dnl
pushdef(`blockoriented',$2)dnl
pushdef(`args',`iarray, jarray,
ifelse(blockoriented,`VBR',`	biarray,bjarray,',`')dnl
ifelse(blockoriented,`BCSR',`	mb,kb,',`')dnl
array, length,
iresult, jresult,
ifelse(blockoriented,`VBR',`	biresult,bjresult,',`')dnl
result')dnl
dnl
foreach(`mtype',RSB_M4_TYPES,`dnl
dnl
	if(`type' == RSB_M4_NUMERICAL_TYPE_PREPROCESSOR_SYMBOL(mtype))
	return RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_NAME(mtype,blockoriented)(args);dnl

	else
dnl
')dnl
dnl
popdef(`blockoriented')dnl
popdef(`args')dnl
dnl
	return RSB_ERR_UNSUPPORTED_TYPE;
}
dnl
popdef(`types')dnl
dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_NAME(TYPE,BLOCKORIENTED)
dnl	--------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates merge function name.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_NAME',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
rsb_do_merge_`'RSB_M4_CHOPSPACES(mtype)`_'blockoriented`'dnl
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_ARGS(TYPE,BLOCKORIENTED)
dnl	--------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates merge function arguments.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_ARGS',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
(
		const rsb_coo_idx_t* RSB_M4_RESTRICT ileft, const rsb_coo_idx_t* RSB_M4_RESTRICT iright,  rsb_coo_idx_t*RSB_M4_RESTRICT iresult,
		const rsb_coo_idx_t* RSB_M4_RESTRICT jleft, const rsb_coo_idx_t* RSB_M4_RESTRICT jright,  rsb_coo_idx_t*RSB_M4_RESTRICT jresult,
ifelse(blockoriented,`VBR',`const rsb_coo_idx_t * RSB_M4_RESTRICT bileft, const rsb_coo_idx_t * RSB_M4_RESTRICT biright, rsb_coo_idx_t * RSB_M4_RESTRICT biresult,',`')dnl
ifelse(blockoriented,`VBR',`const rsb_coo_idx_t * RSB_M4_RESTRICT bjleft, const rsb_coo_idx_t * RSB_M4_RESTRICT bjright, rsb_coo_idx_t * RSB_M4_RESTRICT bjresult,',`')dnl
ifelse(blockoriented,`BCSR',`const rsb_coo_idx_t mb, const rsb_coo_idx_t kb,',`')dnl
		const mtype* left, const mtype* RSB_M4_RESTRICT right,  mtype* RSB_M4_RESTRICT result,
dnl		rsb_coo_idx_t left_index, rsb_coo_idx_t right_index, rsb_coo_idx_t result_index, 
dnl		rsb_coo_idx_t left_mod, rsb_coo_idx_t right_mod, rsb_coo_idx_t result_mod )dnl
		rsb_nnz_idx_t left_length,
		rsb_nnz_idx_t right_length )dnl
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_PROTOTYPE(TYPE,BLOCKORIENTED)
dnl	-------------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates merge function prototype.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_PROTOTYPE',`
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
void RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_NAME(mtype,blockoriented)dnl
RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_ARGS(mtype,blockoriented)
dnl
popdef(`blockoriented')dnl
popdef(`mtype')
dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION(TYPE,BLOCKORIENTED)
dnl	---------------------------------------------------------------
dnl	Expands to the mergesort on coordinates merge function function.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION',`
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_PROTOTYPE(mtype,blockoriented)
{
	/*!
	 * \ingroup gr_util
	 * The merge function for our blockoriented matrix coefficients sorting.
	 *
	 * NOTE :This function is the mergesort bottleneck.
	 */
dnl	rsb_nnz_idx_t left_length=left_mod;
dnl	rsb_nnz_idx_t right_length = right_mod;
	register int left_index=0, right_index=0, result_index=0;
	
	/*
	+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
	          |<-  length ----->|
dnl	<--------------- mod ------------------------->
	          ^- index
	 */

dnl #define LEFT_ADVANCE		left_index =( left_index+1)% left_mod; left_length-- ;
dnl #define RIGHT_ADVANCE		right_index=(right_index+1)%right_mod; right_length--;
dnl #define RESULT_ADVANCE		result_index =( result_index+1)% result_mod;

#define LEFT_ADVANCE		left_index =( left_index+1); left_length-- ;
#define RIGHT_ADVANCE		right_index=(right_index+1); right_length--;
#define RESULT_ADVANCE		result_index =( result_index+1);

ifelse(blockoriented,`VBR',`dnl
#define RESULT_APPEND(IEL,JEL,BIEL,BJEL,EL)	\
',`dnl
#define RESULT_APPEND(IEL,JEL,EL)	\
')dnl
	iresult[result_index]=(IEL);  \
	jresult[result_index]=(JEL);  \
	result[result_index]=( EL);  \
ifelse(blockoriented,`VBR',`dnl
	biresult[result_index]=(BIEL);  \
',`')dnl
ifelse(blockoriented,`VBR',`dnl
	bjresult[result_index]=(BJEL);  \
',`')dnl
	RESULT_ADVANCE;

#define LRESULT_APPEND	\
	iresult[result_index]=ileft[left_index];\
	jresult[result_index]=jleft[left_index];\
ifelse(blockoriented,`VBR',`dnl
	biresult[result_index]=bileft[left_index];  \
',`')dnl
ifelse(blockoriented,`VBR',`dnl
	bjresult[result_index]=bjleft[left_index];  \
',`')dnl
	result[ result_index]= left[left_index];\
	RESULT_ADVANCE; \
	LEFT_ADVANCE;

#define RRESULT_APPEND	\
	iresult[result_index]=iright[right_index];\
	jresult[result_index]=jright[right_index];\
ifelse(blockoriented,`VBR',`dnl
	biresult[result_index]=biright[right_index];  \
',`')dnl
ifelse(blockoriented,`VBR',`dnl
	bjresult[result_index]=bjright[right_index];  \
',`')dnl
	 result[result_index]= right[right_index];\
	RESULT_ADVANCE; \
	RIGHT_ADVANCE; 

	while( left_length > 0 && right_length > 0)
	if(
	ifelse(blockoriented,`VBR',`
		bileft[left_index] < biright[right_index] ||
		(	bileft[left_index] == biright[right_index]	&&
			bjleft[left_index] <= bjright[right_index]	)
		)
	')dnl
	ifelse(blockoriented,`CSR',`
		ileft[left_index] < iright[right_index] ||
		(	ileft[left_index] == iright[right_index]	&&
			jleft[left_index] <= jright[right_index]	)
		)
	')dnl
	ifelse(blockoriented,`BCSR',`
		ileft[left_index]/mb < iright[right_index]/mb ||
		(	ileft[left_index]/mb == iright[right_index]/mb	&&
			jleft[left_index]/kb <= jright[right_index]/kb	)
		)
	')dnl
	ifelse(blockoriented,`PACK',`
		ileft[left_index].spmv_uauz < iright[right_index].v )
	')dnl
	{
		LRESULT_APPEND
	}
	else
	{
		RRESULT_APPEND
	}

	while( left_length  > 0 )
	{
		LRESULT_APPEND
	}
	while( right_length  > 0 )
	{
		RRESULT_APPEND
	}
#undef LEFT_ADVANCE
#undef RIGHT_ADVANCE
#undef RESULT_ADVANCE
#undef RESULT_APPEND
#undef LRESULT_APPEND
#undef RRESULT_APPEND

}
dnl
popdef(`blockoriented')dnl
popdef(`type')dnl
dnl
')
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_NAME(TYPE,BLOCKORIENTED)
dnl	--------------------------------------------------------------
dnl	Expands to the mergesort on coordinates function name.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_NAME',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
dnl rsb_do_mergesort_`'mtype`'dnl
rsb_do_mergesort_`'RSB_M4_CHOPSPACES(mtype)`_'blockoriented`'dnl
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_ARGS(TYPE,BLOCKORIENTED)
dnl	--------------------------------------------------------------
dnl	Expands to the mergesort on coordinates function arguments.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_ARGS',`dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
(
	rsb_coo_idx_t *RSB_M4_RESTRICT iarray,
	rsb_coo_idx_t *RSB_M4_RESTRICT jarray,
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *RSB_M4_RESTRICT biarray,
',`')dnl
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *RSB_M4_RESTRICT bjarray,
',`')dnl
ifelse(blockoriented,`BCSR',`	rsb_coo_idx_t mb, rsb_coo_idx_t kb,
',`')dnl
	mtype *array,
	rsb_nnz_idx_t length, 
	rsb_coo_idx_t *RSB_M4_RESTRICT iresult,
	rsb_coo_idx_t *RSB_M4_RESTRICT jresult,
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *RSB_M4_RESTRICT biresult,
',`')dnl
ifelse(blockoriented,`VBR',`	rsb_coo_idx_t *RSB_M4_RESTRICT bjresult,
',`')dnl
	mtype *RSB_M4_RESTRICT result)
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
')dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_PROTOTYPE(TYPE,BLOCKORIENTED)
dnl	-------------------------------------------------------------------
dnl	Expands to the mergesort on coordinates function prototype.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_PROTOTYPE',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
rsb_err_t RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_NAME(`mtype',`blockoriented')dnl
RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_ARGS(`mtype',`blockoriented')dnl
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
')dnl
dnl
dnl
dnl
dnl	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION(TYPE,BLOCKORIENTED)
dnl	---------------------------------------------------------
dnl	Expands to the block oriented mergesort on coordinates function
dnl	for VBR partitioning.
dnl	The blocking is specified as a function argument.
dnl
define(`RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION',`dnl
dnl
pushdef(`mtype',$1)dnl
pushdef(`blockoriented',$2)dnl
dnl
RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_PROTOTYPE(mtype,blockoriented)
dnl
{
	/*!
	 *	\ingroup gr_util
	 *	This function will sort the non zero elements of a sparse blocked
	 *      mtype matrix.
	 *      It will read row and column indices arrays, the values array,
	 *	and will sort them in separate output arrays.
	 *
	 *	NOTE : This function could be optimized.
	 *
	 * 	\param iarray  the input  row    indices array
	 * 	\param jarray  the input  column indices array
	 * 	\param array   the input  mtype array
	 * 	\param iresult the output row    indices array
	 * 	\param jresult the output column indices array
	 * 	\param result  the output values array
ifelse(blockoriented,`VBR',`dnl
	 * 	\param biarray  the input  block row    indices array
	 * 	\param bjarray  the input  block column indices array
	 * 	\param biresult the output block row    indices array
	 * 	\param bjresult the output block column indices array
')dnl
	 *	Will sort  thethree arrays (iarray, jarray, array) following the 
	 *	criteria :
	 *
	 * 	(ia1,ja1)<=(ia2,ja2) iff (ia1<ia2) or ( (ia1==ia2) and (ja1<ja2) )
	 * 	i.e.: C (row major) ordering
	 */

	rsb_nnz_idx_t middle;
	rsb_coo_idx_t so=sizeof(rsb_coo_idx_t);

	rsb_coo_idx_t * ileft  ;
	rsb_coo_idx_t * iright ;
ifelse(blockoriented,`VBR',`
	rsb_coo_idx_t * bileft  ;
	rsb_coo_idx_t * biright ;
',`')dnl
	rsb_coo_idx_t * jleft  ;
	rsb_coo_idx_t * jright ;
ifelse(blockoriented,`VBR',`
	rsb_coo_idx_t * bjleft  ;
	rsb_coo_idx_t * bjright ;
',`')dnl
ifelse(RSB_M4_WANT_OMP,`1',`dnl
	size_t tn=0;
dnl	size_t nt;
')dnl
	mtype * left  ;
	mtype * right ;
	
#define LIMIT 1
	if(length==LIMIT)
	{
		*iresult = *iarray;
		*jresult = *jarray;
ifelse(blockoriented,`VBR',`
		*biresult = *biarray;
		*bjresult = *bjarray;
',`')dnl
		*(mtype*)result = *(mtype*)array;
	}
	if(length<=LIMIT) return RSB_ERR_NO_ERROR;
#undef LIMIT
	middle = length/2;

ifelse(blockoriented,`VBR',`
	bileft  = biarray;
	bjleft  = bjarray;
	biright = biarray+middle;
	bjright = bjarray+middle;
',`')dnl
	left  = array;
	right  = array+middle;
	ileft  = iarray;
	jleft  = jarray;
	iright = iarray+middle;
	jright = jarray+middle;

ifelse(`0',`1',`dnl 20121016 
ifelse(RSB_M4_WANT_OMP,`1',`dnl
`#'dnl
dnl       pragma omp parallel num_threads(rsb_global_session_handle.rsb_g_threads)
       pragma omp parallel
	/*	FIXME : warning : experimental */
	{
	tn = omp_get_thread_num();
	nt = omp_get_num_threads();
	if(tn==0)
')dnl
',`dnl
/* 20121016 commented out omp usage because broke serial compilation  */
	{
')dnl
	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_NAME(mtype,blockoriented)
	( ileft, jleft,
ifelse(blockoriented,`VBR',`dnl
		bileft, bjleft,
',`')dnl
ifelse(blockoriented,`BCSR',` mb, kb, ',`')dnl
		left,   middle,
	        iresult  ,       jresult,
ifelse(blockoriented,`VBR',`dnl
		biresult, bjresult,
',`')dnl
		result         );

ifelse(RSB_M4_WANT_OMP,`1',`dnl
	if(tn==1)
')dnl
	RSB_M4_MERGESORT_ON_COORDINATES_FUNCTION_NAME(mtype,blockoriented)
	(iright, jright,
ifelse(blockoriented,`VBR',`dnl
		biright, bjright,
',`')dnl
ifelse(blockoriented,`BCSR',` mb, kb, ',`')dnl
		right, length-middle,  iresult+middle  ,jresult+middle,
ifelse(blockoriented,`VBR',`dnl
		biresult+middle, bjresult+middle,
',`')dnl
	((mtype*)result)+middle  );
ifelse(RSB_M4_WANT_OMP,`1',`dnl
	}
',`dnl
	}
')dnl

	RSB_MEMCPY(ileft ,iresult       ,so*middle);
	RSB_MEMCPY(jleft ,jresult       ,so*middle);
ifelse(blockoriented,`VBR',`
	RSB_MEMCPY(bileft ,biresult       ,so*middle);
	RSB_MEMCPY(bjleft ,bjresult       ,so*middle);
',`')dnl
	RSB_MEMCPY(  left, result       ,sizeof(mtype)*middle);
	RSB_MEMCPY(iright,iresult+middle,so*(length-middle));
	RSB_MEMCPY(jright,jresult+middle,so*(length-middle));
ifelse(blockoriented,`VBR',`
	RSB_MEMCPY(biright ,biresult+middle       ,so*(length-middle));
	RSB_MEMCPY(bjright ,bjresult+middle       ,so*(length-middle));
',`')dnl
	RSB_MEMCPY( right, ((mtype*)result)+middle ,sizeof(mtype)*(length-middle));

	RSB_M4_MERGESORT_ON_COORDINATES_MERGE_FUNCTION_NAME(mtype,blockoriented)dnl
		(
			ileft,iright,iresult,
			jleft,jright,jresult,
ifelse(blockoriented,`BCSR',`	mb,kb,')
ifelse(blockoriented,`VBR',`dnl
			bileft, biright, biresult,
',`')dnl
ifelse(blockoriented,`VBR',`dnl
			bjleft, bjright, bjresult,
',`')dnl
			left, right, result,
dnl			0,0,0,
dnl			middle,length-middle,length
			middle,length-middle
			);
	return RSB_ERR_NO_ERROR;	/* ! */
}
dnl
popdef(`blockoriented')dnl
popdef(`mtype')dnl
dnl
')
dnl
dnl
dnl