File: Bdef.h

package info (click to toggle)
blacs-mpi 1.1-28.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,320 kB
  • ctags: 2,031
  • sloc: fortran: 14,968; ansic: 12,353; makefile: 531; sh: 1
file content (1673 lines) | stat: -rw-r--r-- 53,657 bytes parent folder | download | duplicates (9)
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
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
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
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
#ifndef BDEF_H
#define BDEF_H 1
/* This file from mpiblacs_patch01 */

/*
 * Include the system dependant and user defined stuff
 */
#include "Bconfig.h"
#ifdef CRAY
#define float double
#include <fortran.h>
#endif
/*
 * ========================================================================
 *                     TYPEDEF'S USED IN THE BLACS
 * ========================================================================
 */

/*
 * ---------------------------------------------------------------------------
 * Define MPI's data types differently depending on whether we are using MPI's
 * fortran or C interface
 * ---------------------------------------------------------------------------
 */
#ifdef UseF77Mpi

#define BI_MPI_Aint     int
#define BI_MPI_Comm     int
#define BI_MPI_Datatype int
#define BI_MPI_Group    int
#define BI_MPI_Op       int
#define BI_MPI_Request  int
#define BI_MPI_Status   int

#else

#define BI_MPI_Aint     MPI_Aint
#define BI_MPI_Comm     MPI_Comm
#define BI_MPI_Datatype MPI_Datatype
#define BI_MPI_Group    MPI_Group
#define BI_MPI_Op       MPI_Op
#define BI_MPI_Request  MPI_Request
#define BI_MPI_Status   MPI_Status

#endif


/*
 * Data type defining a scope for the BLACS
 */
typedef struct bLaCsScOpE BLACSSCOPE;
struct bLaCsScOpE
{
   BI_MPI_Comm comm;
   int ScpId, MaxId, MinId;
   int Np, Iam;
};
/*
 * Data type defining a context for the BLACS
 */
typedef struct bLaCsCoNtExT BLACSCONTEXT;
struct bLaCsCoNtExT
{
   BLACSSCOPE rscp, cscp, ascp, pscp; /* row, column, all, and pt2pt scopes */
   BLACSSCOPE *scp;                   /* pointer to present scope */
#if (BI_TransComm == BONEHEAD)
#ifdef UseF77Mpi
   MPI_Comm C_comm;
#else
   int *F77_comm;
#endif
#endif
   int TopsRepeat;                    /* Use only repeatable topologies? */
   int TopsCohrnt;                    /* Use only coherent topologies? */
   int Nb_bs, Nr_bs;           /* for bcast general tree and multiring tops */
   int Nb_co, Nr_co;           /* for combine general tree and multiring tops */
};

/*
 *  Define the fortran 77 data types COMPLEX*8 (SCOMPLEX)
 *  and COMPLEX*16 (DCOMPLEX).
 */
typedef struct {double r, i;} DCOMPLEX;
typedef struct {float r, i;} SCOMPLEX;

/*
 *  These variables will be defined to be MPI datatypes for complex and double
 *  complex if we are using the C interface to MPI.  If we use the fortran
 *  interface, we need to declare the contants array.  I'm too lazy to declare
 *  these guys external in every file that needs them.
 */
#ifndef GlobalVars

#ifdef UseF77Mpi
   extern int *BI_F77_MPI_CONSTANTS, *BI_F77_MPI_COMM_WORLD;
#else
   extern BI_MPI_Datatype BI_MPI_COMPLEX, BI_MPI_DOUBLE_COMPLEX;
   extern int *BI_F77_MPI_COMM_WORLD;
#endif

#endif

/*
 *  Definition of buffer type for BLACS' asynchronous operations
 */
typedef struct bLaCbUfF BLACBUFF;
struct bLaCbUfF
{
   char *Buff;             /* send/recv buffer */
   int Len;                /* length of buffer in bytes */
   int nAops;              /* number of asynchronous operations out of buff */
   BI_MPI_Request *Aops;   /* list of async. operations out of buff */
   BI_MPI_Datatype dtype;  /* data type of buffer */
   int N;                  /* number of elements of data type in buff */
   BLACBUFF *prev, *next;  /* pointer to the other BLACBUFF in queue */
};

/*
 * Pointer to the combine's vector-vector functions
 */
#ifdef __STDC__
typedef void (*VVFUNPTR)(int, char *, char *);
typedef void (*SDRVPTR)(BLACSCONTEXT *, int, int, BLACBUFF *);
#else
typedef void (*VVFUNPTR)();
typedef void (*SDRVPTR)();
#endif

/*
 * ========================================================================
 *                             MACRO CONSTANTS
 * ========================================================================
 */
/*
 * ----------------------------------------------
 * Define MPI's constants for fortran77 interface
 * ----------------------------------------------
 */
#ifdef UseF77Mpi

/*
 *  return codes
 */
#define BI_MPI_SUCCESS                 BI_F77_MPI_CONSTANTS[0]
#define BI_MPI_ERR_UNKNOWN             BI_F77_MPI_CONSTANTS[1]
#define BI_MPI_ERR_OTHER               BI_F77_MPI_CONSTANTS[2]
#define BI_MPI_ERR_INTERN              BI_F77_MPI_CONSTANTS[3]

/*
 *  Assorted constants
 */
#define BI_MPI_ANY_SOURCE              BI_F77_MPI_CONSTANTS[4]
#define BI_MPI_UNDEFINED               BI_F77_MPI_CONSTANTS[5]

/*
 *  Status size and reserved index values
 */
#define BI_MPI_STATUS_SIZE             BI_F77_MPI_CONSTANTS[6]
#define BI_MPI_SOURCE                  BI_F77_MPI_CONSTANTS[7]
#define BI_MPI_TAG                     BI_F77_MPI_CONSTANTS[8]

/*
 *  Elementary datatypes
 */
#define BI_MPI_INT                     BI_F77_MPI_CONSTANTS[9]
#define BI_MPI_FLOAT                   BI_F77_MPI_CONSTANTS[10]
#define BI_MPI_DOUBLE                  BI_F77_MPI_CONSTANTS[11]
#define BI_MPI_COMPLEX                 BI_F77_MPI_CONSTANTS[12]
#define BI_MPI_DOUBLE_COMPLEX          BI_F77_MPI_CONSTANTS[13]
#define BI_MPI_PACKED                  BI_F77_MPI_CONSTANTS[14]
#define BI_MPI_BYTE                    BI_F77_MPI_CONSTANTS[15]

/*
 * Reserved communicators
 */
#define BI_MPI_COMM_WORLD              BI_F77_MPI_CONSTANTS[16]
#define BI_MPI_COMM_NULL               BI_F77_MPI_CONSTANTS[17]

/*
 * Environmental inquiry keys
 */
#define BI_MPI_TAG_UB BI_F77_MPI_CONSTANTS[18]

/*
 * Collective operations
 */
#define BI_MPI_MAX                     BI_F77_MPI_CONSTANTS[19]
#define BI_MPI_MIN                     BI_F77_MPI_CONSTANTS[20]
#define BI_MPI_SUM                     BI_F77_MPI_CONSTANTS[21]

/*
 * NULL handles
 */
#define BI_MPI_REQUEST_NULL          BI_F77_MPI_CONSTANTS[22]

/*
 * Data types to use in the combine operations
 */
#define BI_DistType                  int
#define BI_MpiDistType               BI_MPI_INT

/*
 * ====================================
 * Define MPI constants for C interface
 * ====================================
 */
#else
/*
 *  return codes
 */
#define BI_MPI_SUCCESS               MPI_SUCCESS
#define BI_MPI_ERR_UNKNOWN           MPI_ERR_UNKNOWN
#define BI_MPI_ERR_OTHER             MPI_ERR_OTHER
#define BI_MPI_ERR_INTERN            MPI_ERR_INTERN

/*
 *  Assorted constants
 */
#define BI_MPI_ANY_SOURCE            MPI_ANY_SOURCE
#define BI_MPI_UNDEFINED             MPI_UNDEFINED

/*
 *  Status size and reserved index values
 */
#define BI_MPI_STATUS_SIZE           1

/*
 *  Elementary datatypes
 */
#define BI_MPI_SHORT                 MPI_SHORT
#define BI_MPI_INT                   MPI_INT
#define BI_MPI_FLOAT                 MPI_FLOAT
#define BI_MPI_DOUBLE                MPI_DOUBLE
#define BI_MPI_PACKED                MPI_PACKED
#define BI_MPI_BYTE                  MPI_BYTE

/*
 * Reserved communicators
 */
#define BI_MPI_COMM_WORLD            MPI_COMM_WORLD
#define BI_MPI_COMM_NULL             MPI_COMM_NULL

/*
 * Environmental inquiry keys
 */
#define BI_MPI_TAG_UB                MPI_TAG_UB

/*
 * Collective operations
 */
#define BI_MPI_MAX                   MPI_MAX
#define BI_MPI_MIN                   MPI_MIN
#define BI_MPI_SUM                   MPI_SUM

/*
 * NULL handles
 */
#define BI_MPI_REQUEST_NULL          MPI_REQUEST_NULL
/*
 * Data types to use in the combine operations
 */
#define BI_DistType                  unsigned short
#define BI_MpiDistType               MPI_UNSIGNED_SHORT

#endif

#define BUFFALIGN    8      /* force all buffers to 8 byte alignment */
#define BANYNODE     BI_MPI_ANY_SOURCE
#define PT2PTID      9976   /* TAG used for point to point */
#define NOTINCONTEXT -1  /* Indicates node called gridmap, but not in grid */
#define MAXNCTXT 10      /* initial guess at max # of contexts */
#define MAXNSYSCTXT 10   /* initial guess at max # of system context */
#define AOPDONE BI_MPI_REQUEST_NULL
#define BUFWAIT 120      /* Length of time to wait for emergency buff */

/*
 * Error codes
 */
#define NORV 1          /* No receiver (only 1 proc in scoped op) */
#define NPOW2 2         /* Number of procs is not a power of 2 */
#define BADSCP 3        /* Scope not row, column or all */

/*
 * Data types
 */
#define INTEGER   3
#define SINGLE    4
#define DOUBLE    6
#define COMPLEX8  5
#define COMPLEX16 7

#define FULLCON 0      /* top is fully connected */

/*
 * Routine types
 */
#define RT_SD    1
#define RT_RV    2
#define RT_BS    3
#define RT_BR    4
#define RT_COMB  5

/*
 * Legal WHAT values for BLACS_SET
 */
#define SGET_SYSCONTXT    0
#define SGET_MSGIDS       1
#define SGET_DEBUGLVL     2
#define SGET_BLACSCONTXT 10
#define SGET_NR_BS       11
#define SGET_NB_BS       12
#define SGET_NR_CO       13
#define SGET_NB_CO       14
#define SGET_TOPSREPEAT  15
#define SGET_TOPSCOHRNT  16

/*
 * These are prototypes for error and warning functions -- I don't want
 * to prototype them in each routine.
 */
#ifdef __STDC__
void BI_BlacsWarn(int ConTxt, int line, char *file, char *form, ...);
void BI_BlacsErr(int ConTxt, int line, char *file, char *form, ...);
int BI_ContxtNum(BLACSCONTEXT *ctxt);
#else
void BI_BlacsWarn();
void BI_BlacsErr();
int BI_ContxtNum();
#endif

/*
 * If we've got an ANSI standard C compiler, we can use void pointers,
 * otherwise use char pointers
 */
#ifdef __STDC__
#define BVOID void
#else
#define BVOID char
#endif

/*
 * ========================================================================
 *     PREPROCESSOR MACRO FUNCTIONS USED FOR OPTIMIZATION & CONVENIENCE
 * ========================================================================
 */

#define Mlowcase(C) ( ((C) > 64 && (C) < 91) ? (C) | 32 : (C) )

/*
 * Slightly modified gridinfo substitute
 */
#define Mgridinfo(ctxt, Ng0, nprow0, npcol0, myrow0, mycol0)\
{\
   (Ng0) = (ctxt)->ascp.Np;\
   (nprow0) = (ctxt)->cscp.Np;\
   (npcol0) = (ctxt)->rscp.Np;\
   (myrow0) = (ctxt)->cscp.Iam;\
   (mycol0) = (ctxt)->rscp.Iam;\
}

/*
 * These routines return coordinates based on nodes number, or node number
 * based on coordinates.  Those routines with v after the M return virtual
 * nodes numbers (i.e., in respect to the grid, not physical node numbers)
 * based on grid coordinates, or grid coordinates based on virtual node numbers.
 */
#define Mpcoord(ctxt, node, prow, pcol)\
{\
   (prow) = (node) / (ctxt)->rscp.Np;\
   (pcol) = (node) % (ctxt)->rscp.Np;\
}
#define Mvpcoord(ctxt, node, prow, pcol) \
        Mpcoord((ctxt), (node), (prow), (pcol));

#define Mkpnum(ctxt, prow, pcol)  ( (prow)*(ctxt)->rscp.Np+(pcol) )
#define Mvkpnum(ctxt, prow, pcol) ( (prow)*(ctxt)->rscp.Np+(pcol) )

/*
 * This macro returns scoped message ID's.
 */
#define Mscopeid(ctxt) (ctxt)->scp->ScpId; \
   if (++(ctxt)->scp->ScpId == (ctxt)->scp->MaxId) \
      (ctxt)->scp->ScpId = (ctxt)->scp->MinId;

/*
 *  Get context, and check for validity if debug level is high
 */
#if (BlacsDebugLvl > 0)
#define MGetConTxt(Context, ctxtptr)\
{\
   extern BLACSCONTEXT **BI_MyContxts;\
   extern int BI_MaxNCtxt;\
   if ( ((Context) >= BI_MaxNCtxt) || ((Context) < 0) )\
      BI_BlacsErr(-1, __LINE__, __FILE__, "Invalid context handle: %d",\
                  (Context));\
   else if (BI_MyContxts[(Context)] == NULL)\
      BI_BlacsErr(-1, __LINE__, __FILE__, "Invalid context, handle=%d",\
                  (Context));\
   (ctxtptr) = BI_MyContxts[(Context)];\
}
#else
#define MGetConTxt(Context, ctxtptr)\
{\
   extern BLACSCONTEXT **BI_MyContxts;\
   (ctxtptr) = BI_MyContxts[(Context)];\
}
#endif
/*
 * This macro handles MPI errors
 */
#if(BlacsDebugLvl > 0)
#define Mmpierror(ierr, rout, ctxt, line, file) \
{ \
   if ( (ierr) != BI_MPI_SUCCESS )\
      BI_BlacsErr(BI_ContxtNum((ctxt)), (line), (file), \
                  "MPI error %d on call to %s", (ierr), (rout)); \
}
#else
#define Mmpierror(ierr, rout, ctxt, line, file)
#endif
/*
 * A small macro useful for debugging
 */
#define ErrPrint \
{ \
   extern int BI_Iam; \
   fprintf(stderr, "%d: line %d of file %s\n", BI_Iam, __LINE__, __FILE__); \
}

/*
 * These macros allow for the funky function declarations and character handling
 * needed on the CRAY to have a C routine callable from fortran
 */
#define F_VOID_FUNC void
#define F_INT_FUNC  int
#define F_DOUBLE_FUNC double

#if (INTFACE == C_CALL)

#define F2C_CharTrans(c) *(c)

#else

#ifdef CRAY
#define F2C_CharTrans(c) *( _fcdtocp((c)) )
#define F_CHAR      _fcd
#else
#define F2C_CharTrans(c) *(c)
#define F_CHAR      char *
#endif

#endif

/*
 *  These macros allow for accessing values and addresses of parameters, which
 *  will be pointers if we're using fortran, and values if we're using C.
 */
#if (INTFACE == C_CALL)
#define Mpval(para) (para)
#define Mpaddress(para) (&(para))
#define Mwalltime Cdwalltime00
#else
#define Mpval(para) (*(para))
#define Mpaddress(para) (para)
#define Mwalltime dwalltime00_
#endif

/*
 * Real and complex absolute values
 */
#define Rabs(x) ( (x) < 0 ? (x) * -1 : (x) )
#define Cabs(z) ( (((z).i) < 0 ? ((z).i) * -1 : ((z).i)) + (((z).r) < 0 ? ((z).r) * -1 : ((z).r)) )

/*
 * Figures the length of packed trapezoidal matrix
 */
#define trsize(diag, m, n, bytes, length)\
{\
   if ( (diag) == 'u' ) (length) = 1;\
   else (length) = 0;\
   if ( (m) > (n) )\
      (length) = ( (n) * ( (m) - (n) ) + ( (n)*(n) ) - ( (n)*(n) )/2 +\
                   (n)/2 - (n) * (length) ) * (bytes);\
   else\
      (length) = ( (m) * ( (n) - (m) ) + ( (m)*(m) ) - ( (m)*(m) )/2 +\
                   (m)/2 - (m) * (length) ) * (bytes);\
}

/*
 * These macros call the correct packing/unpacking routines
 */
#define BI_cmvcopy(m, n, A, lda, buff) \
        BI_smvcopy(2*(m), (n), (float *) (A), 2*(lda), (float *) (buff))
#define BI_cvmcopy(m, n, A, lda, buff) \
        BI_svmcopy(2*(m), (n), (float *) (A), 2*(lda), (float *) (buff))
#define BI_zmvcopy(m, n, A, lda, buff) \
        BI_dmvcopy(2*(m), (n), (double *) (A), 2*(lda), (double *) (buff))
#define BI_zvmcopy(m, n, A, lda, buff) \
        BI_dvmcopy(2*(m), (n), (double *) (A), 2*(lda), (double *) (buff))

#if (F77_CALL_C == ADD_)
/*
 * These defines set up the naming scheme required to have a fortran 77
 * routine call a C routine (which is what the BLACS are written in).
 * No redefinition necessary to have following Fortran to C interface:
 *           FORTRAN CALL               C DECLARATION
 *           call dgebs2d(...)          void dgebs2d_(...)
 */
#endif

#if (F77_CALL_C == NOCHANGE)
/*
 * These defines set up the naming scheme required to have a fortran 77
 * routine call a C routine (which is what the BLACS are written in)
 * for the following Fortran to C interface:
 *           FORTRAN CALL               C DECLARATION
 *           call dgebs2d(...)          void dgebs2d(...)
 */

/*
 * Support routines
 */
#define blacs_pinfo_                   blacs_pinfo
#define blacs_setup_                   blacs_setup
#define setpvmtids_                    setpvmtids
#define blacs_set_                     blacs_set
#define blacs_get_                     blacs_get
#define blacs_gridinit_                blacs_gridinit
#define blacs_gridmap_                 blacs_gridmap
#define ksendid_                       ksendid
#define krecvid_                       krecvid
#define kbsid_                         kbsid
#define kbrid_                         kbrid
#define blacs_freebuff_                blacs_freebuff
#define blacs_gridexit_                blacs_gridexit
#define blacs_abort_                   blacs_abort
#define blacs_exit_                    blacs_exit
#define blacs_gridinfo_                blacs_gridinfo
#define blacs_pnum_                    blacs_pnum
#define blacs_pcoord_                  blacs_pcoord
#define dcputime00_                    dcputime00
#define dwalltime00_                   dwalltime00
#define blacs_barrier_                 blacs_barrier

/*
 * Main, type dependent, routines
 */
#define igesd2d_   igesd2d
#define igerv2d_   igerv2d
#define igebs2d_   igebs2d
#define igebr2d_   igebr2d
#define itrsd2d_   itrsd2d
#define itrrv2d_   itrrv2d
#define itrbs2d_   itrbs2d
#define itrbr2d_   itrbr2d
#define igsum2d_   igsum2d
#define igamx2d_   igamx2d
#define igamn2d_   igamn2d
#define sgesd2d_   sgesd2d
#define sgerv2d_   sgerv2d
#define sgebs2d_   sgebs2d
#define sgebr2d_   sgebr2d
#define strsd2d_   strsd2d
#define strrv2d_   strrv2d
#define strbs2d_   strbs2d
#define strbr2d_   strbr2d
#define sgsum2d_   sgsum2d
#define sgamx2d_   sgamx2d
#define sgamn2d_   sgamn2d
#define dgesd2d_   dgesd2d
#define dgerv2d_   dgerv2d
#define dgebs2d_   dgebs2d
#define dgebr2d_   dgebr2d
#define dtrsd2d_   dtrsd2d
#define dtrrv2d_   dtrrv2d
#define dtrbs2d_   dtrbs2d
#define dtrbr2d_   dtrbr2d
#define dgsum2d_   dgsum2d
#define dgamx2d_   dgamx2d
#define dgamn2d_   dgamn2d
#define cgesd2d_   cgesd2d
#define cgerv2d_   cgerv2d
#define cgebs2d_   cgebs2d
#define cgebr2d_   cgebr2d
#define ctrsd2d_   ctrsd2d
#define ctrrv2d_   ctrrv2d
#define ctrbs2d_   ctrbs2d
#define ctrbr2d_   ctrbr2d
#define cgsum2d_   cgsum2d
#define cgamx2d_   cgamx2d
#define cgamn2d_   cgamn2d
#define zgesd2d_   zgesd2d
#define zgerv2d_   zgerv2d
#define zgebs2d_   zgebs2d
#define zgebr2d_   zgebr2d
#define ztrsd2d_   ztrsd2d
#define ztrrv2d_   ztrrv2d
#define ztrbs2d_   ztrbs2d
#define ztrbr2d_   ztrbr2d
#define zgsum2d_   zgsum2d
#define zgamx2d_   zgamx2d
#define zgamn2d_   zgamn2d

/*
 * If we are using the fortran interface to MPI, need to redefine the names
 */
#ifdef UseF77Mpi
#define mpi_abort_                     mpi_abort
#define mpi_allreduce_                 mpi_allreduce
#define bi_f77_mpi_attr_get_           bi_f77_mpi_attr_get
#define mpi_barrier_                   mpi_barrier
#define mpi_bcast_                     mpi_bcast
#define mpi_comm_create_               mpi_comm_create
#define mpi_comm_dup_                  mpi_comm_dup
#define mpi_comm_free_                 mpi_comm_free
#define mpi_comm_group_                mpi_comm_group
#define mpi_comm_rank_                 mpi_comm_rank
#define mpi_comm_size_                 mpi_comm_size
#define mpi_comm_split_                mpi_comm_split
#define mpi_error_class_               mpi_error_class
#define mpi_finalize_                  mpi_finalize
#define mpi_get_count_                 mpi_get_count
#define mpi_group_incl_                mpi_group_incl
#define mpi_group_free_                mpi_group_free
#define mpi_init_                      mpi_init
#define bi_f77_mpi_initialized_        bi_f77_mpi_initialized
#define mpi_irecv_                     mpi_irecv
#define mpi_isend_                     mpi_isend
#define bi_f77_mpi_op_create_          bi_f77_mpi_op_create
#define mpi_op_free_                   mpi_op_free
#define mpi_pack_                      mpi_pack
#define mpi_pack_size_                 mpi_pack_size
#define mpi_recv_                      mpi_recv
#define mpi_reduce_                    mpi_reduce
#define mpi_rsend_                     mpi_rsend
#define mpi_send_                      mpi_send
#define mpi_sendrecv_                  mpi_sendrecv
#define bi_f77_mpi_test_               bi_f77_mpi_test
#define bi_f77_mpi_testall_            bi_f77_mpi_testall
#define mpi_type_commit_               mpi_type_commit
#define mpi_type_contiguous_           mpi_type_contiguous
#define mpi_type_free_                 mpi_type_free
#define mpi_type_indexed_              mpi_type_indexed
#define mpi_type_struct_               mpi_type_struct
#define mpi_type_vector_               mpi_type_vector
#define mpi_unpack_                    mpi_unpack
#define mpi_waitall_                   mpi_waitall
#define mpi_wtime_                     mpi_wtime
#define bi_f77_get_constants_          bi_f77_get_constants
#define bi_f77_init_                   bi_f77_init
#else
#define mpi_init_                    mpi_init
#define bi_f77_get_constants_        bi_f77_get_constants
#define bi_f77_init_                 bi_f77_init
#if (BI_TransComm == BONEHEAD)
#define mpi_comm_group_              mpi_comm_group
#define mpi_group_translate_ranks_   mpi_group_translate_ranks
#endif
#endif

#endif

#if (F77_CALL_C == UPCASE)
/*
 * These defines set up the naming scheme required to have a fortran 77
 * routine call a C routine (which is what the BLACS are written in)
 * for the following Fortran to C interface:
 *           FORTRAN CALL               C DECLARATION
 *           call dgebs2d(...)          void DGEBS2D(...)
 */
/*
 * Support routines
 */
#define blacs_pinfo_                   BLACS_PINFO
#define blacs_setup_                   BLACS_SETUP
#define setpvmtids_                    SETPVMTIDS
#define blacs_set_                     BLACS_SET
#define blacs_get_                     BLACS_GET
#define blacs_gridinit_                BLACS_GRIDINIT
#define blacs_gridmap_                 BLACS_GRIDMAP
#define ksendid_                       KSENDID
#define krecvid_                       KRECVID
#define kbsid_                         KBSID
#define kbrid_                         KBRID
#define blacs_freebuff_                BLACS_FREEBUFF
#define blacs_gridexit_                BLACS_GRIDEXIT
#define blacs_abort_                   BLACS_ABORT
#define blacs_exit_                    BLACS_EXIT
#define blacs_gridinfo_                BLACS_GRIDINFO
#define blacs_pnum_                    BLACS_PNUM
#define blacs_pcoord_                  BLACS_PCOORD
#define dcputime00_                    DCPUTIME00
#define dwalltime00_                   DWALLTIME00
#define blacs_barrier_                 BLACS_BARRIER

/*
 * Main, type dependent, routines
 */
#define igesd2d_   IGESD2D
#define igerv2d_   IGERV2D
#define igebs2d_   IGEBS2D
#define igebr2d_   IGEBR2D
#define itrsd2d_   ITRSD2D
#define itrrv2d_   ITRRV2D
#define itrbs2d_   ITRBS2D
#define itrbr2d_   ITRBR2D
#define igsum2d_   IGSUM2D
#define igamx2d_   IGAMX2D
#define igamn2d_   IGAMN2D
#define sgesd2d_   SGESD2D
#define sgerv2d_   SGERV2D
#define sgebs2d_   SGEBS2D
#define sgebr2d_   SGEBR2D
#define strsd2d_   STRSD2D
#define strrv2d_   STRRV2D
#define strbs2d_   STRBS2D
#define strbr2d_   STRBR2D
#define sgsum2d_   SGSUM2D
#define sgamx2d_   SGAMX2D
#define sgamn2d_   SGAMN2D
#define dgesd2d_   DGESD2D
#define dgerv2d_   DGERV2D
#define dgebs2d_   DGEBS2D
#define dgebr2d_   DGEBR2D
#define dtrsd2d_   DTRSD2D
#define dtrrv2d_   DTRRV2D
#define dtrbs2d_   DTRBS2D
#define dtrbr2d_   DTRBR2D
#define dgsum2d_   DGSUM2D
#define dgamx2d_   DGAMX2D
#define dgamn2d_   DGAMN2D
#define cgesd2d_   CGESD2D
#define cgerv2d_   CGERV2D
#define cgebs2d_   CGEBS2D
#define cgebr2d_   CGEBR2D
#define ctrsd2d_   CTRSD2D
#define ctrrv2d_   CTRRV2D
#define ctrbs2d_   CTRBS2D
#define ctrbr2d_   CTRBR2D
#define cgsum2d_   CGSUM2D
#define cgamx2d_   CGAMX2D
#define cgamn2d_   CGAMN2D
#define zgesd2d_   ZGESD2D
#define zgerv2d_   ZGERV2D
#define zgebs2d_   ZGEBS2D
#define zgebr2d_   ZGEBR2D
#define ztrsd2d_   ZTRSD2D
#define ztrrv2d_   ZTRRV2D
#define ztrbs2d_   ZTRBS2D
#define ztrbr2d_   ZTRBR2D
#define zgsum2d_   ZGSUM2D
#define zgamx2d_   ZGAMX2D
#define zgamn2d_   ZGAMN2D

/*
 * If we are using the fortran interface to MPI, need to redefine the names
 */
#ifdef UseF77Mpi
#define mpi_abort_                     MPI_ABORT
#define mpi_allreduce_                 MPI_ALLREDUCE
#define bi_f77_mpi_attr_get_           BI_F77_MPI_ATTR_GET
#define mpi_barrier_                   MPI_BARRIER
#define mpi_bcast_                     MPI_BCAST
#define mpi_comm_create_               MPI_COMM_CREATE
#define mpi_comm_dup_                  MPI_COMM_DUP
#define mpi_comm_free_                 MPI_COMM_FREE
#define mpi_comm_group_                MPI_COMM_GROUP
#define mpi_comm_rank_                 MPI_COMM_RANK
#define mpi_comm_size_                 MPI_COMM_SIZE
#define mpi_comm_split_                MPI_COMM_SPLIT
#define mpi_error_class_               MPI_ERROR_CLASS
#define mpi_finalize_                  MPI_FINALIZE
#define mpi_get_count_                 MPI_GET_COUNT
#define mpi_group_incl_                MPI_GROUP_INCL
#define mpi_group_free_                MPI_GROUP_FREE
#define mpi_init_                      MPI_INIT
#define bi_f77_mpi_initialized_        BI_F77_MPI_INITIALIZED
#define mpi_irecv_                     MPI_IRECV
#define mpi_isend_                     MPI_ISEND
#define bi_f77_mpi_op_create_          BI_F77_MPI_OP_CREATE
#define mpi_op_free_                   MPI_OP_FREE
#define mpi_pack_                      MPI_PACK
#define mpi_pack_size_                 MPI_PACK_SIZE
#define mpi_recv_                      MPI_RECV
#define mpi_reduce_                    MPI_REDUCE
#define mpi_rsend_                     MPI_RSEND
#define mpi_send_                      MPI_SEND
#define mpi_sendrecv_                  MPI_SENDRECV
#define bi_f77_mpi_test_               BI_F77_MPI_TEST
#define bi_f77_mpi_testall_            BI_F77_MPI_TESTALL
#define mpi_type_commit_               MPI_TYPE_COMMIT
#define mpi_type_contiguous_           MPI_TYPE_CONTIGUOUS
#define mpi_type_free_                 MPI_TYPE_FREE
#define mpi_type_indexed_              MPI_TYPE_INDEXED
#define mpi_type_struct_               MPI_TYPE_STRUCT
#define mpi_type_vector_               MPI_TYPE_VECTOR
#define mpi_unpack_                    MPI_UNPACK
#define mpi_waitall_                   MPI_WAITALL
#define mpi_wtime_                     MPI_WTIME
#define bi_f77_get_constants_          BI_F77_GET_CONSTANTS
#define bi_f77_init_                   BI_F77_INIT
#else
#define mpi_init_                    MPI_INIT
#define bi_f77_init_                 BI_F77_INIT
#define bi_f77_get_constants_        BI_F77_GET_CONSTANTS
#if (BI_TransComm == BONEHEAD)
#define mpi_comm_group_             MPI_COMM_GROUP
#define mpi_group_translate_ranks_  MPI_GROUP_TRANSLATE_RANKS
#endif
#endif

#endif

#if (F77_CALL_C == F77ISF2C)
/*
 * These defines set up the naming scheme required to have a fortran 77
 * routine call a C routine (which is what the BLACS are written in)
 * for systems where the fortran "compiler" is actually f2c (a fortran
 * to C conversion utility).
 */
/*
 * Initialization routines
 */
#define blacs_pinfo_    blacs_pinfo__
#define blacs_setup_    blacs_setup__
#define blacs_set_      blacs_set__
#define blacs_get_      blacs_get__
#define blacs_gridinit_ blacs_gridinit__
#define blacs_gridmap_  blacs_gridmap__
/*
 * Destruction routines
 */
#define blacs_freebuff_ blacs_freebuff__
#define blacs_gridexit_ blacs_gridexit__
#define blacs_abort_    blacs_abort__
#define blacs_exit_     blacs_exit__
/*
 * Informational & misc.
 */
#define blacs_gridinfo_ blacs_gridinfo__
#define blacs_pnum_     blacs_pnum__
#define blacs_pcoord_   blacs_pcoord__
#define blacs_barrier_  blacs_barrier__

/*
 * If we are using the fortran interface to MPI, need to redefine the names
 */
#ifdef UseF77Mpi
#define mpi_abort_                     mpi_abort__
#define mpi_allreduce_                 mpi_allreduce__
#define mpi_barrier_                   mpi_barrier__
#define mpi_bcast_                     mpi_bcast__
#define mpi_init_                      mpi_init__
#define mpi_finalize_                  mpi_finalize__
#define mpi_irecv_                     mpi_irecv__
#define mpi_pack_                      mpi_pack__
#define mpi_isend_                     mpi_isend__
#define mpi_recv_                      mpi_recv__
#define mpi_reduce_                    mpi_reduce__
#define mpi_rsend_                     mpi_rsend__
#define mpi_send_                      mpi_send__
#define mpi_sendrecv_                  mpi_sendrecv__
#define mpi_unpack_                    mpi_unpack__
#define mpi_waitall_                   mpi_waitall__
#define mpi_wtime_                     mpi_wtime__

#define mpi_comm_create_               mpi_comm_create__
#define mpi_comm_dup_                  mpi_comm_dup__
#define mpi_comm_free_                 mpi_comm_free__
#define mpi_comm_group_                mpi_comm_group__
#define mpi_comm_rank_                 mpi_comm_rank__
#define mpi_comm_size_                 mpi_comm_size__
#define mpi_comm_split_                mpi_comm_split__
#define mpi_error_class_               mpi_error_class__
#define mpi_get_count_                 mpi_get_count__
#define mpi_group_incl_                mpi_group_incl__
#define mpi_group_free_                mpi_group_free__
#define mpi_op_free_                   mpi_op_free__
#define mpi_pack_size_                 mpi_pack_size__
#define mpi_type_commit_               mpi_type_commit__
#define mpi_type_contiguous_           mpi_type_contiguous__
#define mpi_type_free_                 mpi_type_free__
#define mpi_type_indexed_              mpi_type_indexed__
#define mpi_type_struct_               mpi_type_struct__
#define mpi_type_vector_               mpi_type_vector__

#define bi_f77_get_constants_          bi_f77_get_constants__
#define bi_f77_init_                   bi_f77_init__
#define mpi_group_translate_ranks_     mpi_group_translate_ranks__
#define bi_f77_mpi_initialized_        bi_f77_mpi_initialized__
#define bi_f77_mpi_test_               bi_f77_mpi_test__
#define bi_f77_mpi_testall_            bi_f77_mpi_testall__

#define bi_f77_mpi_attr_get_           bi_f77_mpi_attr_get__
#define bi_f77_mpi_op_create_          bi_f77_mpi_op_create__
#else
#define mpi_init_                   mpi_init__
#define bi_f77_get_constants_       bi_f77_get_constants__
#define bi_f77_init_                bi_f77_init__
#if (BI_TransComm == BONEHEAD)
#define mpi_comm_group_             mpi_comm_group__
#define mpi_group_translate_ranks_  mpi_group_translate_ranks__
#endif
#endif

#endif

/*
 * ==========================================================================
 * Prototype the fortran interface MPI functions if they are going to be used
 * ==========================================================================
 */
#ifdef UseF77Mpi

#ifdef __STDC__
   F_VOID_FUNC mpi_abort_(int*, int*, int*);
   F_VOID_FUNC mpi_allreduce_(void*, void*, int*, int*, int*, int*, int*);
   F_VOID_FUNC bi_f77_mpi_attr_get_(int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_barrier_(int*, int*);
   F_VOID_FUNC mpi_bcast_(void*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_comm_create_(int*, int*, int*, int*);
   F_VOID_FUNC mpi_comm_dup_(int*, int*, int*);
   F_VOID_FUNC mpi_comm_free_(int*, int*);
   F_VOID_FUNC mpi_comm_group_(int*, int*, int*);
   F_VOID_FUNC mpi_comm_rank_(int*, int*, int*);
   F_VOID_FUNC mpi_comm_size_(int*, int*, int*);
   F_VOID_FUNC mpi_comm_split_(int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_error_class_(int*, int*, int*);
   F_VOID_FUNC mpi_finalize_(int*);
   F_VOID_FUNC mpi_get_count_(int*, int*, int*, int*);
   F_VOID_FUNC mpi_group_incl_(int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_group_free_(int*, int*);
   F_VOID_FUNC mpi_init_(int*);
   F_VOID_FUNC bi_f77_mpi_initialized_(int*, int*);
   F_VOID_FUNC mpi_irecv_(void*, int*, int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_isend_(void*, int*, int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC bi_f77_mpi_op_create_(void func(void*, void*, int*, int*),
                                     int*, int*, int*);
   F_VOID_FUNC mpi_op_free_(int*, int*);
   F_VOID_FUNC mpi_pack_(void*, int*, int*, void*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_pack_size_(int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_recv_(void *, int*, int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_reduce_(void*, void*, int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_rsend_(void*, int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_send_(void*, int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_sendrecv_(void*, int*, int*, int*, int*, void*, int*, int*,
                             int*, int*, int*, int*, int*);
   F_VOID_FUNC bi_f77_mpi_test_(int*, int*, int*, int*);
   F_VOID_FUNC bi_f77_mpi_testall_(int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_type_commit_(int*, int*);
   F_VOID_FUNC mpi_type_contiguous_(int*, int*, int*, int*);
   F_VOID_FUNC mpi_type_free_(int*, int*);
   F_VOID_FUNC mpi_type_indexed_(int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_type_struct_(int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_type_vector_(int*, int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_unpack_(void*, int*, int*, void*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_waitall_(int*, int*, int*, int*);
   F_DOUBLE_FUNC mpi_wtime(void);
#else
   F_VOID_FUNC mpi_abort_();
   F_VOID_FUNC mpi_allreduce_();
   F_VOID_FUNC bi_f77_mpi_attr_get_();
   F_VOID_FUNC mpi_barrier_();
   F_VOID_FUNC mpi_bcast_();
   F_VOID_FUNC mpi_comm_create_();
   F_VOID_FUNC mpi_comm_dup_();
   F_VOID_FUNC mpi_comm_free_();
   F_VOID_FUNC mpi_comm_group_();
   F_VOID_FUNC mpi_comm_rank_();
   F_VOID_FUNC mpi_comm_size_();
   F_VOID_FUNC mpi_comm_split_();
   F_VOID_FUNC mpi_error_class_();
   F_VOID_FUNC mpi_finalize_();
   F_VOID_FUNC mpi_get_count_();
   F_VOID_FUNC mpi_group_incl_();
   F_VOID_FUNC mpi_group_free_();
   F_VOID_FUNC mpi_init_();
   F_VOID_FUNC bi_f77_mpi_initialized_();
   F_VOID_FUNC mpi_irecv_();
   F_VOID_FUNC mpi_isend_();
   F_VOID_FUNC bi_f77_mpi_op_create_();
   F_VOID_FUNC mpi_op_free_();
   F_VOID_FUNC mpi_pack_();
   F_VOID_FUNC mpi_pack_size_();
   F_VOID_FUNC mpi_recv_();
   F_VOID_FUNC mpi_reduce_();
   F_VOID_FUNC mpi_rsend_();
   F_VOID_FUNC mpi_send_();
   F_VOID_FUNC mpi_sendrecv_();
   F_VOID_FUNC bi_f77_mpi_test_();
   F_VOID_FUNC bi_f77_mpi_testall_();
   F_VOID_FUNC mpi_type_commit_();
   F_VOID_FUNC mpi_type_contiguous_();
   F_VOID_FUNC mpi_type_free_();
   F_VOID_FUNC mpi_type_indexed_();
   F_VOID_FUNC mpi_type_struct_();
   F_VOID_FUNC mpi_type_vector_();
   F_VOID_FUNC mpi_unpack_();
   F_VOID_FUNC mpi_waitall_();
   F_DOUBLE_FUNC BI_MPI_Wtime();
#endif

/*
 * If we are using the C interface, still may need some f77 functions to do
 * context translation
 */
#else

#if (BI_TransComm == BONEHEAD)

#ifdef __STDC__
   F_VOID_FUNC mpi_comm_create_(int*, int*, int*, int*);
   F_VOID_FUNC mpi_comm_free_(int*, int*);
   F_VOID_FUNC mpi_comm_group_(int*, int*, int*);
   F_VOID_FUNC mpi_comm_size_(int*, int*, int*);
   F_VOID_FUNC mpi_group_incl_(int*, int*, int*, int*, int*);
   F_VOID_FUNC mpi_group_free_(int*, int*);
   F_VOID_FUNC mpi_group_translate_ranks_(int*, int*, int*, int*, int*, int*);
#else
   F_VOID_FUNC mpi_comm_create_();
   F_VOID_FUNC mpi_comm_free_();
   F_VOID_FUNC mpi_comm_group_();
   F_VOID_FUNC mpi_comm_size_();
   F_VOID_FUNC mpi_group_incl_();
   F_VOID_FUNC mpi_group_free_();
   F_VOID_FUNC mpi_group_translate_ranks_();
#endif

#endif

#endif

/*
 * ================================================
 * Define MPI functions for C and fortran interface
 * ================================================
 */

#ifdef UseF77Mpi
#define BI_MPI_Abort(comm_, errcode_, ierr_)\
{ \
   mpi_abort_(&(comm_), &(errcode_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_ABORT", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Abort(comm_, errcode_, ierr_)\
{ \
   (ierr_) = MPI_Abort((comm_), (errcode_));  \
   Mmpierror((ierr_), "MPI_Abort", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Allreduce(sbuf_, rbuf_, count_, dtype_, op_, comm_, ierr_)\
{ \
   mpi_allreduce_((sbuf_), (rbuf_), &(count_), &(dtype_), &(op_), &(comm_), \
                  &(ierr_)); \
   Mmpierror((ierr_), "MPI_ALLREDUCE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Allreduce(sbuf_, rbuf_, count_, dtype_, op_, comm_, ierr_)\
{ \
   (ierr_) = MPI_Allreduce((sbuf_), (rbuf_), (count_), (dtype_), (op_), \
                           (comm_)); \
   Mmpierror((ierr_), "MPI_Allreduce", NULL, __LINE__, __FILE__); \
}
#endif

/*
 * Need to be sure to set attr_ to pointing at int before call . . .
 * int *iptr=&i; BI_MPI_Attr_get(... &iptr ...);
 */
#ifdef UseF77Mpi
#define BI_MPI_Attr_get(comm_, keyval_, attr_, flag_, ierr_) \
{ \
   bi_f77_mpi_attr_get_(&(comm_), &(keyval_), (int *) *(attr_), (flag_), \
                        &(ierr_)); \
   Mmpierror((ierr_), "MPI_ATTR_GET", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Attr_get(comm_, keyval_, attr_, flag_, ierr_) \
{ \
   (ierr_) = MPI_Attr_get((comm_), (keyval_), (attr_), (flag_)); \
   Mmpierror((ierr_), "MPI_Attr_get", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Barrier(comm_, ierr_) \
{ \
   mpi_barrier_(&(comm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_BARRIER", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Barrier(comm_, ierr_) \
{ \
   (ierr_) = MPI_Barrier((comm_)); \
   Mmpierror((ierr_), "MPI_Barrier", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Bcast(buff_, count_, dtype_, root_, comm_, ierr_) \
{ \
   mpi_bcast_((buff_), &(count_), &(dtype_), &(root_), &(comm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_BCAST", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Bcast(buff_, count_, dtype_, root_, comm_, ierr_) \
{ \
   (ierr_) = MPI_Bcast((buff_), (count_), (dtype_), (root_), (comm_)); \
   Mmpierror((ierr_), "MPI_Bcast", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Comm_create(comm_, group_, newcomm_, ierr_) \
{ \
   mpi_comm_create_(&(comm_), &(group_), (newcomm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_COMM_CREATE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Comm_create(comm_, group_, newcomm_, ierr_) \
{ \
   (ierr_) = MPI_Comm_create((comm_), (group_), (newcomm_)); \
   Mmpierror((ierr_), "MPI_Comm_create", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Comm_dup(comm_, newcomm_, ierr_) \
{ \
   mpi_comm_dup_(&(comm_), (newcomm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_COMM_DUP", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Comm_dup(comm_, newcomm_, ierr_) \
{ \
   (ierr_) = MPI_Comm_dup((comm_), (newcomm_)); \
   Mmpierror((ierr_), "MPI_Comm_dup", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Comm_free(comm_, ierr_) \
{ \
   mpi_comm_free_((comm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_COMM_FREE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Comm_free(comm_, ierr_) \
{ \
   (ierr_) = MPI_Comm_free((comm_)); \
   Mmpierror((ierr_), "MPI_Comm_free", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Comm_group(comm_, grp_, ierr_) \
{ \
   mpi_comm_group_(&(comm_), (grp_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_COMM_GROUP", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Comm_group(comm_, grp_, ierr_) \
{ \
   (ierr_) = MPI_Comm_group((comm_), (grp_)); \
   Mmpierror((ierr_), "MPI_Comm_group", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Comm_rank(comm_, rank_, ierr_) \
{ \
   mpi_comm_rank_(&(comm_), (rank_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_COMM_RANK", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Comm_rank(comm_, rank_, ierr_) \
{ \
   (ierr_) = MPI_Comm_rank((comm_), (rank_)); \
   Mmpierror((ierr_), "MPI_Comm_rank", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Comm_size(comm_, size_, ierr_) \
{ \
   mpi_comm_size_(&(comm_), (size_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_COMM_SIZE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Comm_size(comm_, size_, ierr_) \
{ \
   (ierr_) = MPI_Comm_size((comm_), (size_)); \
   Mmpierror((ierr_), "MPI_Comm_size", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Comm_split(comm_, color_, key_, newcomm_, ierr_) \
{ \
   mpi_comm_split_(&(comm_), &(color_), &(key_), (newcomm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_COMM_SPLIT", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Comm_split(comm_, color_, key_, newcomm_, ierr_) \
{ \
   (ierr_) = MPI_Comm_split((comm_), (color_), (key_), (newcomm_)); \
   Mmpierror((ierr_), "MPI_Comm_split", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Error_class(errcode_, errclass_, ierr_) \
{ \
   mpi_error_class_(&(errcode_), (errclass_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_ERROR_CLASS", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Error_class(errcode_, errclass_, ierr_) \
{ \
   (ierr_) = MPI_Error_class((errcode_), (errclass_)); \
   Mmpierror((ierr_), "MPI_Error_class", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Finalize(ierr_) \
{ \
   mpi_finalize_(&(ierr_)); \
   Mmpierror((ierr_), "MPI_FINALIZE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Finalize(ierr_) \
{ \
   (ierr_) = MPI_Finalize(); \
   Mmpierror((ierr_), "MPI_Finalize", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Get_count(stat_, dtype_, count_, ierr_) \
{ \
   mpi_get_count_((stat_), &(dtype_), (count_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_GET_COUNT", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Get_count(stat_, dtype_, count_, ierr_) \
{ \
   (ierr_) = MPI_Get_count((stat_), (dtype_), (count_)); \
   Mmpierror((ierr_), "MPI_Get_count", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Group_free(grp_, ierr_) \
{ \
   mpi_group_free_((grp_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_GROUP_FREE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Group_free(grp_, ierr_) \
{ \
   (ierr_) = MPI_Group_free(grp_); \
   Mmpierror((ierr_), "MPI_Group_free", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Group_incl(grp_, n_, ranks_, newgrp_, ierr_) \
{ \
   mpi_group_incl_(&(grp_), &(n_), (ranks_), (newgrp_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_GROUP_INCL", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Group_incl(grp_, n_, ranks_, newgrp_, ierr_) \
{ \
   (ierr_) = MPI_Group_incl((grp_), (n_), (ranks_), (newgrp_)); \
   Mmpierror((ierr_), "MPI_Group_incl", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Group_translate_ranks(grp1_, n_, ranks1_, grp2_, ranks2_, ierr_) \
{ \
   MPI_Group_translate_ranks(&(grp1_), &(n_), (ranks1_), &(grp2_), (ranks2_),\
                             &(ierr_)); \
   Mmpierror((ierr_), "MPI_GROUP_TRANSLATE_RANKS", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Group_translate_ranks(grp1_, n_, ranks1_, grp2_, ranks2_, ierr_) \
{ \
   (ierr_) = MPI_Group_translate_ranks((grp1_), (n_), (ranks1_), (grp2_),\
                                       (ranks2_)); \
   Mmpierror((ierr_), "MPI_Group_translate_ranks", NULL, __LINE__, __FILE__); \
}
#endif

/*
 *  The BLACS always call f77's mpi_init.  If the user is using C, he should
 *  explicitly call MPI_Init . . .
 */
#define BI_MPI_Init(argc_, argv_, ierr_) \
{ \
   mpi_init_(&(ierr_)); \
   Mmpierror((ierr_), "MPI_INIT", NULL, __LINE__, __FILE__); \
}

#ifdef UseF77Mpi
#define BI_MPI_Initialized(flag_, ierr_) \
{ \
   bi_f77_mpi_initialized_((flag_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_INITIALIZED", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Initialized(flag_, ierr_) \
{ \
   (ierr_) = MPI_Initialized((flag_)); \
   Mmpierror((ierr_), "MPI_Initialized", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Irecv(buf_, count_, dtype_, src_, tag_, comm_, req_, ierr_) \
   mpi_irecv_((buf_), &(count_), &(dtype_), &(src_), &(tag_), &(comm_), \
              (req_), &(ierr_))
#else
#define BI_MPI_Irecv(buf_, count_, dtype_, src_, tag_, comm_, req_, ierr_) \
   (ierr_) = MPI_Irecv((buf_), (count_), (dtype_), (src_), (tag_), (comm_), \
                       (req_))
#endif

#ifdef UseF77Mpi
#define BI_MPI_Isend(buf_, count_, dtype_, dest_, tag_, comm_, req_, ierr_) \
   mpi_isend_((buf_), &(count_), &(dtype_), &(dest_), &(tag_), &(comm_), \
              (req_), &(ierr_));
#else
#define BI_MPI_Isend(buf_, count_, dtype_, dest_, tag_, comm_, req_, ierr_) \
   (ierr_) = MPI_Isend((buf_), (count_), (dtype_), (dest_), (tag_), (comm_), \
                       (req_))
#endif

#ifdef UseF77Mpi
#define BI_MPI_Op_create(func_, commute_, op_, ierr_) \
{ \
   bi_f77_mpi_op_create_((func_), &(commute_), (op_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_OP_CREATE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Op_create(func_, commute_, op_, ierr_) \
{ \
   (ierr_) = MPI_Op_create((func_), (commute_), (op_)); \
   Mmpierror((ierr_), "MPI_Op_create", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Op_free(op_, ierr_) \
{ \
   mpi_op_free_((op_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_OP_FREE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Op_free(op_, ierr_) \
{ \
   (ierr_) = MPI_Op_free((op_)); \
   Mmpierror((ierr_), "MPI_Op_free", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Pack(inbuf_, incount_, dtype_, outbuf_, outsiz_, pos_, comm_, ierr_) \
{ \
   mpi_pack_((inbuf_), &(incount_), &(dtype_), (outbuf_), &(outsiz_), \
             (pos_), &(comm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_PACK", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Pack(inbuf_, incount_, dtype_, outbuf_, outsiz_, pos_, comm_, ierr_) \
{ \
   (ierr_) = MPI_Pack((inbuf_), (incount_), (dtype_), (outbuf_), (outsiz_), \
                      (pos_), (comm_)); \
   Mmpierror((ierr_), "MPI_Pack", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Pack_size(incount_, dtype_, comm_, size_, ierr_) \
{ \
   mpi_pack_size_(&(incount_), &(dtype_), &(comm_), (size_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_PACK_SIZE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Pack_size(incount_, dtype_, comm_, size_, ierr_) \
{ \
   (ierr_) = MPI_Pack_size((incount_), (dtype_), (comm_), (size_)); \
   Mmpierror((ierr_), "MPI_Pack_size", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Recv(buf_, count_, dtype_, src_, tag_, comm_, stat_, ierr_) \
{ \
   mpi_recv_((buf_), &(count_), &(dtype_), &(src_), &(tag_), &(comm_), \
             (stat_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_RECV", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Recv(buf_, count_, dtype_, src_, tag_, comm_, stat_, ierr_) \
{ \
   (ierr_) = MPI_Recv((buf_), (count_), (dtype_), (src_), (tag_), (comm_), \
                      (stat_)); \
   Mmpierror((ierr_), "MPI_Recv", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Reduce(sbuf_, rbuf_, count_, dtype_, op_, root_, comm_, ierr_) \
{ \
   mpi_reduce_((sbuf_), (rbuf_), &(count_), &(dtype_), &(op_), &(root_), \
               &(comm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_REDUCE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Reduce(sbuf_, rbuf_, count_, dtype_, op_, root_, comm_, ierr_) \
{ \
   (ierr_) = MPI_Reduce((sbuf_), (rbuf_), (count_), (dtype_), (op_), (root_), \
                        (comm_)); \
   Mmpierror((ierr_), "MPI_Reduce", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Rsend(buf_, count_, dtype_, dest_, tag_, comm_, ierr_) \
{ \
   mpi_rsend_((buf_), &(count_), &(dtype_), &(dest_), &(tag_), &(comm_), \
              &(ierr_)); \
   Mmpierror((ierr_), "MPI_RSEND", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Rsend(buf_, count_, dtype_, dest_, tag_, comm_, ierr_) \
{ \
   (ierr_) = MPI_Rsend((buf_), (count_), (dtype_), (dest_), (tag_), (comm_)); \
   Mmpierror((ierr_), "MPI_Rsend", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Send(buf_, count_, dtype_, dest_, tag_, comm_, ierr_) \
{ \
   mpi_send_((buf_), &(count_), &(dtype_), &(dest_), &(tag_), &(comm_), \
             &(ierr_)); \
   Mmpierror((ierr_), "MPI_SEND", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Send(buf_, count_, dtype_, dest_, tag_, comm_, ierr_) \
{ \
   (ierr_) = MPI_Send((buf_), (count_), (dtype_), (dest_), (tag_), (comm_)); \
   Mmpierror((ierr_), "MPI_Send", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Sendrecv(sbuf_, scount_, stype_, dest_, stag_, rbuf_, rcount_, rtype_, src_, rtag_, comm_, stat_, ierr_) \
{ \
   mpi_sendrecv_((sbuf_), &(scount_), &(stype_), &(dest_), &(stag_), \
                 (rbuf_), &(rcount_), &(rtype_), &(src_), &(rtag_), \
                 &(comm_), (stat_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_SENDRECV", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Sendrecv(sbuf_, scount_, stype_, dest_, stag_, rbuf_, rcount_, rtype_, src_, rtag_, comm_, stat_, ierr_) \
{ \
   (ierr_) = MPI_Sendrecv((sbuf_), (scount_), (stype_), (dest_), (stag_), \
                          (rbuf_), (rcount_), (rtype_), (src_), (rtag_), \
                          (comm_), (stat_)); \
   Mmpierror((ierr_), "MPI_Sendrecv", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Test(req_, flag_, stat_, ierr_) \
{ \
   bi_f77_mpi_test_(&(req_), (flag_), (stat_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_TEST", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Test(req_, flag_, stat_, ierr_) \
{ \
   (ierr_) = MPI_Test((req_), (flag_), (stat_)); \
   Mmpierror((ierr_), "MPI_Test", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Testall(count_, reqs_, flag_, stats_, ierr_) \
{ \
   bi_f77_mpi_testall_(&(count_), (reqs_), (flag_), (stats_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_TESTALL", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Testall(count_, reqs_, flag_, stats_, ierr_) \
{ \
   (ierr_) = MPI_Testall((count_), (reqs_), (flag_), (stats_)); \
   Mmpierror((ierr_), "MPI_Testall", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Type_commit(dtype_, ierr_) \
{ \
   mpi_type_commit_((dtype_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_TYPE_COMMIT", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Type_commit(dtype_, ierr_) \
{ \
   (ierr_) = MPI_Type_commit((dtype_)); \
   Mmpierror((ierr_), "MPI_Type_commit", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Type_contiguous(count_, oldtype_, newtype_, ierr_) \
{ \
   mpi_type_contiguous_(&(count_), &(oldtype_), (newtype_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_TYPE_CONTIGUOUS", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Type_contiguous(count_, oldtype_, newtype_, ierr_) \
{ \
   (ierr_) = MPI_Type_contiguous((count_), (oldtype_), (newtype_)); \
   Mmpierror((ierr_), "MPI_Type_contiguous", NULL, __LINE__, __FILE__); \
}
#endif

/*
 * Some versions of mpich and its derivitives cannot handle 0 byte typedefs,
 * so we set type MPI_BYTE as a flag for a 0 byte message
 */
#ifdef ZeroByteTypeBug

#ifdef UseF77Mpi
#define BI_MPI_Type_free(dtype_, ierr_) \
{ \
   if ( *(dtype_) != BI_MPI_BYTE) \
   { \
      mpi_type_free_((dtype_), &(ierr_)); \
      Mmpierror((ierr_), "MPI_TYPE_FREE", NULL, __LINE__, __FILE__); \
   } \
}
#else
#define BI_MPI_Type_free(dtype_, ierr_) \
{ \
   if ( *(dtype_) != BI_MPI_BYTE) \
   { \
      (ierr_) = MPI_Type_free((dtype_)); \
      Mmpierror((ierr_), "MPI_Type_free", NULL, __LINE__, __FILE__); \
   } \
}
#endif

#else

#ifdef UseF77Mpi
#define BI_MPI_Type_free(dtype_, ierr_) \
{ \
   mpi_type_free_((dtype_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_TYPE_FREE", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Type_free(dtype_, ierr_) \
{ \
   (ierr_) = MPI_Type_free((dtype_)); \
   Mmpierror((ierr_), "MPI_Type_free", NULL, __LINE__, __FILE__); \
}
#endif

#endif

#ifdef UseF77Mpi
#define BI_MPI_Type_indexed(count_, lens_, disp_, oldtype_, newtype_, ierr_) \
{ \
   mpi_type_indexed_(&(count_), (lens_), (disp_), &(oldtype_), (newtype_), \
                     &(ierr_)); \
   Mmpierror((ierr_), "MPI_TYPE_INDEXED", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Type_indexed(count_, lens_, disp_, oldtype_, newtype_, ierr_) \
{ \
   (ierr_) = MPI_Type_indexed((count_), (lens_), (disp_), (oldtype_), \
                              (newtype_)); \
   Mmpierror((ierr_), "MPI_Type_indexed", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Type_struct(count_, lens_, disps_, types_, newtype_, ierr_) \
{ \
   mpi_type_struct_(&(count_), (lens_), (disps_), (types_), (newtype_), \
                   &(ierr_)); \
   Mmpierror((ierr_), "MPI_TYPE_STRUCT", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Type_struct(count_, lens_, disps_, types_, newtype_, ierr_) \
{ \
   (ierr_) = MPI_Type_struct((count_), (lens_), (disps_), (types_), \
                             (newtype_)); \
   Mmpierror((ierr_), "MPI_Type_struct", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Type_vector(count_, len_, stride_, oldtype_, newtype_, ierr_) \
{ \
   mpi_type_vector_(&(count_), &(len_), &(stride_), &(oldtype_), (newtype_), \
                    &(ierr_)); \
   Mmpierror((ierr_), "MPI_TYPE_VECTOR", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Type_vector(count_, len_, stride_, oldtype_, newtype_, ierr_) \
{ \
   (ierr_) = MPI_Type_vector((count_), (len_), (stride_), (oldtype_), \
                             (newtype_)); \
   Mmpierror((ierr_), "MPI_Type_vector", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Unpack(inbuf_, insize_, pos_, outbuf_, outcount_, dtype_, comm_, ierr_) \
{ \
   mpi_unpack_((inbuf_), &(insize_), (pos_), (outbuf_), &(outcount_), \
               &(dtype_), &(comm_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_UNPACK", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Unpack(inbuf_, insize_, pos_, outbuf_, outcount_, dtype_, comm_, ierr_) \
{ \
   (ierr_) = MPI_Unpack((inbuf_), (insize_), (pos_), (outbuf_), (outcount_), \
                        (dtype_), (comm_)); \
   Mmpierror((ierr_), "MPI_Unpack", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Waitall(count_, reqs_, stats_, ierr_) \
{ \
   mpi_waitall_(&(count_), (reqs_), (stats_), &(ierr_)); \
   Mmpierror((ierr_), "MPI_WAITALL", NULL, __LINE__, __FILE__); \
}
#else
#define BI_MPI_Waitall(count_, reqs_, stats_, ierr_) \
{ \
   (ierr_) = MPI_Waitall((count_), (reqs_), (stats_)); \
   Mmpierror((ierr_), "MPI_Waitall", NULL, __LINE__, __FILE__); \
}
#endif

#ifdef UseF77Mpi
#define BI_MPI_Wtime mpi_wtime_
#else
#define BI_MPI_Wtime MPI_Wtime
#endif

#ifdef CRAY
#ifndef UseF77Mpi
#undef  BI_MPI_FLOAT
#define BI_MPI_FLOAT BI_MPI_DOUBLE
#endif
#endif

#endif