aboutsummaryrefslogtreecommitdiff
blob: 20d4787d79dc494aa63f9b1b23bafac97a1fb83f (plain)
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
diff -Naur bash-4.3/builtins/circle.def mpibash-4.3/builtins/circle.def
--- bash-4.3/builtins/circle.def	1969-12-31 17:00:00.000000000 -0700
+++ mpibash-4.3/builtins/circle.def	2014-05-13 11:27:37.314100671 -0600
@@ -0,0 +1,620 @@
+This file is circle.def, from which is created circle.c.
+It implements all of the "circle_*" builtins in Bash.
+
+$PRODUCES circle.c
+
+#include <config.h>
+
+#include <stdio.h>
+#if defined (HAVE_UNISTD_H)
+#  ifdef _MINIX
+#    include <sys/types.h>
+#  endif
+#  include <unistd.h>
+#endif
+
+#include "../bashintl.h"
+#include "../shell.h"
+#include "common.h"
+#include "bashgetopt.h"
+#include <libcircle.h>
+
+extern int running_trap, trap_saved_exit_value;
+
+static int circle_rank;          /* Rank in the Libcircle job */
+static SHELL_VAR *create_func = NULL;   /* User-defined callback function for CIRCLE_cb_create. */
+static SHELL_VAR *process_func = NULL;  /* User-defined callback function for CIRCLE_cb_process. */
+static SHELL_VAR *reduce_init_func = NULL;  /* User-defined callback function for CIRCLE_cb_reduce_init. */
+static SHELL_VAR *reduce_fini_func = NULL;  /* User-defined callback function for CIRCLE_cb_reduce_fini. */
+static SHELL_VAR *reduce_op_func = NULL;   /* User-defined callback function for CIRCLE_cb_reduce_op. */
+static CIRCLE_handle *current_handle = NULL;   /* Active handle within a callback or NULL if not within a callback */
+static int within_reduction = 0;           /* 1=within a reduction callback; 0=not */
+
+/* Return with a usage message if no arguments remain. */
+#define YES_ARGS(LIST)                          \
+  if ((LIST) == 0)                              \
+    {                                           \
+      builtin_usage ();                         \
+      return (EX_USAGE);                        \
+    }
+
+/* Perform the same operation as bind_variable, but with VALUE being a
+ * number, not a string. */
+static SHELL_VAR *
+bind_variable_number (name, value, flags)
+     const char *name;
+     long value;
+     int flags;
+{
+  char numstr[25];    /* String version of VALUE */
+
+  sprintf (numstr, "%ld", value);
+  return bind_variable (name, numstr, flags);
+}
+
+/* Invoke the user-defined creation-callback function (create_func). */
+static void
+internal_create_func (handle)
+     CIRCLE_handle *handle;
+{
+  WORD_LIST *funcargs;
+
+  if (create_func == NULL)
+    return;
+  current_handle = handle;
+  funcargs = make_word_list (make_word ("cb_create"), NULL);
+  execute_shell_function (create_func, funcargs);
+  dispose_words (funcargs);
+  current_handle = NULL;
+}
+
+/* Invoke the user-defined process-callback function (process_func). */
+static void
+internal_process_func (handle)
+     CIRCLE_handle *handle;
+{
+  WORD_LIST *funcargs;
+
+  if (process_func == NULL)
+    return;
+  current_handle = handle;
+  funcargs = make_word_list (make_word ("cb_process"), NULL);
+  execute_shell_function (process_func, funcargs);
+  dispose_words (funcargs);
+  current_handle = NULL;
+}
+
+/* Invoke the user-defined reduction-initiation callback function
+ * (reduce_init_func). */
+static void
+internal_reduce_init_func (void)
+{
+  WORD_LIST *funcargs;
+
+  if (reduce_init_func == NULL)
+    return;
+  within_reduction = 1;
+  funcargs = make_word_list (make_word ("cb_reduce_init"), NULL);
+  execute_shell_function (reduce_init_func, funcargs);
+  dispose_words (funcargs);
+  within_reduction = 0;
+}
+
+/* Invoke the user-defined reduction callback function
+ * (reduce_op_func). */
+static void
+internal_reduce_op_func (buf1, size1, buf2, size2)
+     const void* buf1;
+     size_t size1;
+     const void* buf2;
+     size_t size2;
+{
+  WORD_LIST *funcargs;
+
+  if (reduce_op_func == NULL)
+    return;
+  within_reduction = 1;
+  funcargs = make_word_list (make_word (buf2), NULL);
+  funcargs = make_word_list (make_word (buf1), funcargs);
+  funcargs = make_word_list (make_word ("cb_reduce_op"), funcargs);
+  execute_shell_function (reduce_op_func, funcargs);
+  dispose_words (funcargs);
+  within_reduction = 0;
+}
+
+/* Invoke the user-defined reduction-finalization callback function
+ * (reduce_fini_func). */
+static void
+internal_reduce_fini_func (buf, size)
+     const void* buf;
+     size_t size;
+{
+  WORD_LIST *funcargs;
+
+  if (reduce_fini_func == NULL)
+    return;
+  funcargs = make_word_list (make_word (buf), NULL);
+  funcargs = make_word_list (make_word ("cb_reduce_fini"), funcargs);
+  execute_shell_function (reduce_fini_func, funcargs);
+  dispose_words (funcargs);
+}
+
+/* Look up a user-provided callback function. */
+static int
+find_callback_function (list, user_func)
+     WORD_LIST *list;
+     SHELL_VAR **user_func;
+{
+  char *funcname;   /* Name of the user-defined function. */
+
+  /* If no argument was provided, nullify the callback function. */
+  if (list == NULL)
+    {
+      *user_func = NULL;
+      return EXECUTION_SUCCESS;
+    }
+
+  /* Get the callback function. */
+  funcname = list->word->word;
+  list = list->next;
+  no_args (list);
+  *user_func = find_function (funcname);
+  if (*user_func == NULL)
+    {
+      builtin_error (_("function %s not found"), funcname);
+      return EXECUTION_FAILURE;
+    }
+  return EXECUTION_SUCCESS;
+}
+
+/* Initialize Libcircle. */
+void
+initialize_libcircle (argc, argv)
+     int argc;
+     char **argv;
+{
+  circle_rank = CIRCLE_init (argc, argv, CIRCLE_DEFAULT_FLAGS);
+  bind_variable_number ("circle_rank", circle_rank, 0);
+  CIRCLE_enable_logging (CIRCLE_LOG_WARN);
+  CIRCLE_cb_create (internal_create_func);
+  CIRCLE_cb_process (internal_process_func);
+  CIRCLE_cb_reduce_init (internal_reduce_init_func);
+  CIRCLE_cb_reduce_op (internal_reduce_op_func);
+  CIRCLE_cb_reduce_fini (internal_reduce_fini_func);
+}
+
+/* Finalize Libcircle. */
+void
+finalize_libcircle (void)
+{
+  CIRCLE_finalize ();
+}
+
+/* ---------------------------------------------------------------------- */
+
+$BUILTIN circle_set_options
+$FUNCTION circle_set_options_builtin
+$SHORT_DOC circle_set_options [flag]...
+Change Libcircle's run-time behavior.
+
+Arguments:
+  FLAG          "split_random", "split_equal", or "create_global"
+
+Multiple flags can be provided.  If no flags are provided, Libcircle
+reverts to its default options.
+
+Exit Status:
+Returns 0 unless an invalid option is given.
+$END
+/*'*/
+
+/* Here is the circle_set_options builtin. */
+int
+circle_set_options_builtin (list)
+     WORD_LIST *list;
+{
+  char *word;          /* One argument */
+  int flags = 0;       /* Flags to pass to CIRCLE_set_options */
+
+  if (list == NULL)
+    flags = CIRCLE_DEFAULT_FLAGS;
+  else
+    while (list != NULL)
+      {
+        word = list->word->word;
+        if (!strcmp (word, "split_random"))
+          flags |= CIRCLE_SPLIT_RANDOM;
+        else if (!strcmp (word, "split_equal"))
+          flags |= CIRCLE_SPLIT_EQUAL;
+        else if (!strcmp (word, "create_global"))
+          flags |= CIRCLE_CREATE_GLOBAL;
+        else
+          {
+            builtin_error (_("invalid flag \"%s\""), word);
+            return (EXECUTION_FAILURE);
+          }
+        list = list->next;
+      }
+  CIRCLE_set_options (flags);
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_cb_create
+$FUNCTION circle_cb_create_builtin
+$SHORT_DOC circle_cb_create [func]
+Register a function that will create work when asked.
+
+Arguments:
+  FUNC          User-defined callback function that will invoke
+                circle_enqueue when called
+
+If FUNC is omitted, no function will be associated with work creation.
+This can be used to nullify a previous circle_cb_create invocation.
+
+Exit Status:
+Returns 0 unless an invalid function is given or an error occurs.
+$END
+
+/* Here is the circle_cb_create builtin. */
+int
+circle_cb_create_builtin (list)
+     WORD_LIST *list;
+{
+  return find_callback_function (list, &create_func);
+}
+
+$BUILTIN circle_cb_process
+$FUNCTION circle_cb_process_builtin
+$SHORT_DOC circle_cb_process [func]
+Register a function that will process work when asked.
+
+Arguments:
+  FUNC          User-defined callback function that will invoke
+                circle_enqueue when called
+
+If FUNC is omitted, no function will be associated with work processing.
+This can be used to nullify a previous circle_cb_process invocation.
+
+Exit Status:
+Returns 0 unless an invalid function is given or an error occurs.
+$END
+
+/* Here is the circle_cb_process builtin. */
+int
+circle_cb_process_builtin (list)
+     WORD_LIST *list;
+{
+  return find_callback_function (list, &process_func);
+}
+
+$BUILTIN circle_begin
+$FUNCTION circle_begin_builtin
+$SHORT_DOC circle_begin
+Begin creation and processing of the distributed work queue.
+
+Exit Status:
+Returns 0 unless an error occurs.
+$END
+
+/* Here is the circle_begin builtin. */
+int
+circle_begin_builtin (list)
+     WORD_LIST *list;
+{
+  no_args (list);
+  CIRCLE_begin ();
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_enqueue
+$FUNCTION circle_enqueue_builtin
+$SHORT_DOC circle_enqueue work
+Enqueue work onto the distributed queue.
+
+Arguments:
+  WORK          "Work" as represented by an arbitrary string of limited
+                size (generally around 4KB)
+
+Exit Status:
+Returns 0 unless an error occurs.
+$END
+
+/* Here is the circle_enqueue builtin. */
+int
+circle_enqueue_builtin (list)
+     WORD_LIST *list;
+{
+  char *work;          /* Work to perform */
+
+  /* Extract the work argument. */
+  YES_ARGS (list);
+  work = list->word->word;
+  list = list->next;
+  no_args (list);
+
+  /* Complain if we're not within a proper callback function. */
+  if (current_handle == NULL)
+    {
+      builtin_error (_("not within a Libcircle \"create\" or \"process\" callback function"));
+      return EXECUTION_FAILURE;
+    }
+
+  /* Enqueue the work. */
+  if (current_handle->enqueue (work) == -1)
+    return EXECUTION_FAILURE;
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_dequeue
+$FUNCTION circle_dequeue_builtin
+$SHORT_DOC circle_dequeue var
+Dequeue work from the distributed queue into a variable.
+
+Arguments:
+  VAR           Variable in which to receive previously enqueued "work"
+
+Exit Status:
+Returns 0 unless an error occurs.
+$END
+
+/* Here is the circle_dequeue builtin. */
+int
+circle_dequeue_builtin (list)
+     WORD_LIST *list;
+{
+  char *varname;       /* Variable in which to store the work string */
+  char work[CIRCLE_MAX_STRING_LEN+1];  /* Work to perform */
+
+  /* Extract the variable-name argument. */
+  YES_ARGS (list);
+  varname = list->word->word;
+  list = list->next;
+  no_args (list);
+
+  /* Complain if we're not within a callback function. */
+  if (current_handle == NULL)
+    {
+      builtin_error (_("not within a Libcircle callback function"));
+      return EXECUTION_FAILURE;
+    }
+
+  /* Dequeue the work and bind it to the given variable. */
+  if (current_handle->dequeue (work) == -1)
+    return EXECUTION_FAILURE;
+  bind_variable (varname, work, 0);
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_enable_logging
+$FUNCTION circle_enable_logging_builtin
+$SHORT_DOC circle_enable_logging log_level
+Change Libcircle's logging verbosity
+
+Arguments:
+  LOG_LEVEL     "fatal", "error", "warning", "info", or "debug"
+
+Exit Status:
+Returns 0 unless an invalid option is given.
+$END
+/*'*/
+
+/* Here is the circle_enable_logging builtin. */
+int
+circle_enable_logging_builtin (list)
+     WORD_LIST *list;
+{
+  char *word;                   /* One argument */
+  CIRCLE_loglevel loglevel;     /* Level to set */
+
+  /* Parse the log level. */
+  YES_ARGS (list);
+  word = list->word->word;
+  if (!strcmp (word, "fatal"))
+    loglevel = CIRCLE_LOG_FATAL;
+  else if (!strcmp (word, "error"))
+    loglevel = CIRCLE_LOG_ERR;
+  else if (!strcmp (word, "warning"))
+    loglevel = CIRCLE_LOG_WARN;
+  else if (!strcmp (word, "info"))
+    loglevel = CIRCLE_LOG_INFO;
+  else if (!strcmp (word, "debug"))
+    loglevel = CIRCLE_LOG_DBG;
+  else
+    {
+      builtin_error (_("invalid log level \"%s\""), word);
+      return (EXECUTION_FAILURE);
+    }
+
+  /* Set the log level. */
+  CIRCLE_enable_logging (loglevel);
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_abort
+$FUNCTION circle_abort_builtin
+$SHORT_DOC circle_abort
+Terminate queue processing.
+
+Exit Status:
+Returns 0 unless an error occurs.
+$END
+
+/* Here is the circle_abort builtin. */
+int
+circle_abort_builtin (list)
+     WORD_LIST *list;
+{
+  no_args (list);
+  CIRCLE_abort ();
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_checkpoint
+$FUNCTION circle_checkpoint_builtin
+$SHORT_DOC circle_checkpoint
+Checkpoint a work queue to disk.
+
+Write a file called circle${circle_rank}.txt containing the current
+queue state of rank ${circle_rank}.  On a later run, a worker can
+invoke circle_read_restarts to repopulate its queue from such a
+checkpoint file.
+
+Exit Status:
+Returns 0 unless an error occurs.
+$END
+/*'*/
+
+/* Here is the circle_checkpoint builtin. */
+int
+circle_checkpoint_builtin (list)
+     WORD_LIST *list;
+{
+  no_args (list);
+  CIRCLE_checkpoint ();
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_read_restarts
+$FUNCTION circle_read_restarts_builtin
+$SHORT_DOC circle_read_restarts
+Repopulate a work queue from a disk checkpoint.
+
+Read queue contents from a file called circle${circle_rank}.txt, which
+was previously produced by circle_checkpoint.
+
+Exit Status:
+Returns 0 unless an error occurs.
+$END
+/*'*/
+
+/* Here is the circle_read_restarts builtin. */
+int
+circle_read_restarts_builtin (list)
+     WORD_LIST *list;
+{
+  no_args (list);
+  CIRCLE_read_restarts ();
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN circle_cb_reduce_init
+$FUNCTION circle_cb_reduce_init_builtin
+$SHORT_DOC circle_cb_reduce_init [func]
+Register a function that will initiate a reduction operation.
+
+Arguments:
+  FUNC          User-defined callback function that will invoke
+                circle_reduce when called
+
+FUNC will be invoked on all ranks.
+
+If FUNC is omitted, no function will be associated with reduction
+initialization.  This can be used to nullify a previous
+circle_cb_reduce_init invocation.
+
+Exit Status:
+Returns 0 unless an invalid function is given or an error occurs.
+$END
+
+/* Here is the circle_cb_reduce_init builtin. */
+int
+circle_cb_reduce_init_builtin (list)
+     WORD_LIST *list;
+{
+  return find_callback_function (list, &reduce_init_func);
+}
+
+$BUILTIN circle_cb_reduce_op
+$FUNCTION circle_cb_reduce_op_builtin
+$SHORT_DOC circle_cb_reduce_op [func]
+Register a function that will complete a reduction operation.
+
+Arguments:
+  FUNC          User-defined callback function that will receive
+                two items to reduce and invoke circle_reduce on
+                the reduced value
+
+If FUNC is omitted, no function will be associated with reduction
+execution.  This can be used to nullify a previous circle_cb_reduce_op
+invocation.
+
+Exit Status:
+Returns 0 unless an invalid function is given or an error occurs.
+$END
+
+/* Here is the circle_cb_reduce_op builtin. */
+int
+circle_cb_reduce_op_builtin (list)
+     WORD_LIST *list;
+{
+  return find_callback_function (list, &reduce_op_func);
+}
+
+$BUILTIN circle_cb_reduce_fini
+$FUNCTION circle_cb_reduce_fini_builtin
+$SHORT_DOC circle_cb_reduce_fini [func]
+Register a function that will complete a reduction operation.
+
+Arguments:
+  FUNC          User-defined callback function that will receive
+                the final reduced data
+
+If FUNC is omitted, no function will be associated with reduction
+completion.  This can be used to nullify a previous
+circle_cb_reduce_fini invocation.
+
+Libcircle guarantees that FUNC will be invoked only on rank 0.
+
+Exit Status:
+Returns 0 unless an invalid function is given or an error occurs.
+$END
+
+/* Here is the circle_cb_reduce_fini builtin. */
+int
+circle_cb_reduce_fini_builtin (list)
+     WORD_LIST *list;
+{
+  return find_callback_function (list, &reduce_fini_func);
+}
+
+$BUILTIN circle_reduce
+$FUNCTION circle_reduce_builtin
+$SHORT_DOC circle_reduce work
+Seed the next phase of a reduction operation
+
+Arguments:
+  WORK          "Work" as represented by an arbitrary string of limited
+                size (generally around 4KB)
+
+This function should be called both by the callback function
+registered with circle_reduce_init and the callback function
+registered with circle_reduce_op.
+
+Exit Status:
+Returns 0 unless an error occurs.
+$END
+
+/* Here is the circle_reduce builtin. */
+int
+circle_reduce_builtin (list)
+     WORD_LIST *list;
+{
+  char *work;          /* Work to perform */
+
+  /* Extract the work argument. */
+  YES_ARGS (list);
+  work = list->word->word;
+  list = list->next;
+  no_args (list);
+
+  /* Complain if we're not within a proper callback function. */
+  if (!within_reduction)
+    {
+      builtin_error (_("not within a Libcircle \"reduce_init\" or \"reduce_op\" callback function"));
+      return EXECUTION_FAILURE;
+    }
+
+  /* Reduce the work. */
+  CIRCLE_reduce (work, strlen (work));
+  return EXECUTION_SUCCESS;
+}
diff -Naur bash-4.3/builtins/Makefile.in mpibash-4.3/builtins/Makefile.in
--- bash-4.3/builtins/Makefile.in	2012-05-25 07:29:19.000000000 -0600
+++ mpibash-4.3/builtins/Makefile.in	2014-05-13 11:27:37.314100671 -0600
@@ -141,7 +141,9 @@
 	  $(srcdir)/times.def $(srcdir)/trap.def $(srcdir)/type.def \
 	  $(srcdir)/ulimit.def $(srcdir)/umask.def $(srcdir)/wait.def \
 	  $(srcdir)/reserved.def $(srcdir)/pushd.def $(srcdir)/shopt.def \
-	  $(srcdir)/printf.def $(srcdir)/complete.def $(srcdir)/mapfile.def
+	  $(srcdir)/printf.def $(srcdir)/complete.def $(srcdir)/mapfile.def \
+	  $(srcdir)/mpi.def \
+@CIRCLE@	  $(srcdir)/circle.def
 
 STATIC_SOURCE = common.c evalstring.c evalfile.c getopt.c bashgetopt.c \
 		getopt.h 
@@ -153,7 +155,9 @@
 	jobs.o kill.o let.o mapfile.o \
 	pushd.o read.o return.o set.o setattr.o shift.o source.o \
 	suspend.o test.o times.o trap.o type.o ulimit.o umask.o \
-	wait.o getopts.o shopt.o printf.o getopt.o bashgetopt.o complete.o
+	wait.o getopts.o shopt.o printf.o getopt.o bashgetopt.o complete.o \
+	mpi.o \
+@CIRCLE@	circle.o
 
 CREATED_FILES = builtext.h builtins.c psize.aux pipesize.h tmpbuiltins.c \
 	tmpbuiltins.h
@@ -317,6 +321,8 @@
 getopts.o: getopts.def
 reserved.o: reserved.def
 complete.o: complete.def
+@CIRCLE@ circle.o: circle.def
+mpi.o: mpi.def
 
 # C files
 bashgetopt.o: ../config.h $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h
@@ -644,6 +650,19 @@
 mapfile.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
 mapfile.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/variables.h $(topdir)/conftypes.h
 mapfile.o: $(topdir)/arrayfunc.h ../pathnames.h
+@CIRCLE@ circle.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
+@CIRCLE@ circle.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
+@CIRCLE@ circle.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
+@CIRCLE@ circle.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+@CIRCLE@ circle.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
+mpi.o: ../config.h ../config-top.h ../config-bot.h ../bashintl.h
+mpi.o: ../include/gettext.h ../shell.h ../config.h ../bashjmp.h
+mpi.o: ../include/posixjmp.h ../command.h ../syntax.h ../general.h
+mpi.o: ../bashtypes.h ../include/chartypes.h ../xmalloc.h ../bashansi.h
+mpi.o: ../error.h ../variables.h ../array.h ../assoc.h ../hashlib.h
+mpi.o: ../conftypes.h ../arrayfunc.h ../quit.h ../sig.h ../include/maxpath.h
+mpi.o: ../unwind_prot.h ../dispose_cmd.h ../make_cmd.h ../include/ocache.h
+mpi.o: ../subst.h ../pathnames.h ../externs.h common.h bashgetopt.h
 
 #bind.o: $(RL_LIBSRC)chardefs.h $(RL_LIBSRC)readline.h $(RL_LIBSRC)keymaps.h
 
diff -Naur bash-4.3/builtins/mpi.def mpibash-4.3/builtins/mpi.def
--- bash-4.3/builtins/mpi.def	1969-12-31 17:00:00.000000000 -0700
+++ mpibash-4.3/builtins/mpi.def	2014-05-13 11:27:37.314100671 -0600
@@ -0,0 +1,744 @@
+This file is mpi.def, from which is created mpi.c.
+It implements all of the "mpi_*" builtins in Bash.
+
+$PRODUCES mpi.c
+
+#include <config.h>
+
+#include <stdio.h>
+#if defined (HAVE_UNISTD_H)
+#  ifdef _MINIX
+#    include <sys/types.h>
+#  endif
+#  include <unistd.h>
+#endif
+
+#include "../bashintl.h"
+#include "../shell.h"
+#include "common.h"
+#include "bashgetopt.h"
+#include <mpi.h>
+
+extern int running_trap, trap_saved_exit_value;
+
+/* Keep track of who we are within MPI_COMM_WORLD. */
+static int mpi_rank;
+static int mpi_num_ranks;
+
+/* Try an MPI operation.  Return with an error message on failure. */
+#define MPI_TRY(STMT)                           \
+  do                                            \
+    {                                           \
+      int mpierr;                               \
+      mpierr = STMT;                            \
+      if (mpierr != MPI_SUCCESS)                \
+        return report_mpi_error (mpierr);       \
+    }                                           \
+  while (0)
+
+/* Return with a usage message if no arguments remain. */
+#define YES_ARGS(LIST)                          \
+  if ((LIST) == 0)                              \
+    {                                           \
+      builtin_usage ();                         \
+      return (EX_USAGE);                        \
+    }
+
+/* Return with an error message if a given variable is read-only or if
+ * we can't write to it for any other reason (e.g., it's defined as a
+ * function). */
+#define REQUIRE_WRITABLE(NAME)                                          \
+  do                                                                    \
+    {                                                                   \
+      SHELL_VAR *bindvar = find_shell_variable (NAME);                  \
+      if (bindvar)                                                      \
+        {                                                               \
+          if (readonly_p (bindvar))                                     \
+            {                                                           \
+              err_readonly (NAME);                                      \
+              return (EXECUTION_FAILURE);                               \
+            }                                                           \
+          if (unbind_variable (NAME) == -1)                             \
+            {                                                           \
+              builtin_error ("Failed to write to variable %s", NAME);   \
+              return (EXECUTION_FAILURE);                               \
+            }                                                           \
+        }                                                               \
+    }                                                                   \
+  while (0)
+
+/* Initialize MPI. */
+void
+initialize_mpi (argc, argv)
+     int argc;
+     char **argv;
+{
+  int init_done;
+
+  MPI_Initialized (&init_done);
+  if (!init_done)
+    MPI_Init (&argc, &argv);
+  MPI_Errhandler_set (MPI_COMM_WORLD, MPI_ERRORS_RETURN);
+  MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);
+  MPI_Comm_size (MPI_COMM_WORLD, &mpi_num_ranks);
+}
+
+/* Finalize MPI. */
+void
+finalize_mpi ()
+{
+  MPI_Finalize ();
+}
+
+/* Parse an operation name into an MPI_Op.  Return 1 on success, 0 on
+ * failure. */
+static int
+parse_operation (char *name, MPI_Op *op)
+{
+  /* Define a mapping from operator names to MPI_Op values. */
+  typedef struct {
+    char *name;        /* Operation name (e.g., "sum") */
+    MPI_Op value;      /* Operation value (e.g., MPI_SUM) */
+  } opname2value_t;
+  static opname2value_t oplist[] = {
+    {"max",    MPI_MAX},
+    {"min",    MPI_MIN},
+    {"sum",    MPI_SUM},
+    {"prod",   MPI_PROD},
+    {"land",   MPI_LAND},
+    {"band",   MPI_BAND},
+    {"lor",    MPI_LOR},
+    {"bor",    MPI_BOR},
+    {"lxor",   MPI_LXOR},
+    {"bxor",   MPI_BXOR},
+    {"maxloc", MPI_MAXLOC},
+    {"minloc", MPI_MINLOC}
+  };
+  size_t i;
+
+  for (i = 0; i < sizeof(oplist)/sizeof(opname2value_t); i++)
+    if (!strcmp(name, oplist[i].name))
+      {
+        *op = oplist[i].value;
+        if (i > 0)
+          {
+            /* As a performance optimization, bubble up the value we
+             * just found. */
+            opname2value_t prev = oplist[i - 1];
+            oplist[i - 1] = oplist[i];
+            oplist[i] = prev;
+          }
+        return 1;
+      }
+  return 0;
+}
+
+/* Report an error to the user and return EXECUTION_FAILURE. */
+static int
+report_mpi_error (mpierr)
+     int mpierr;
+{
+  char errstr[MPI_MAX_ERROR_STRING];
+  int errstrlen;
+
+  MPI_Error_string (mpierr, errstr, &errstrlen);
+  builtin_error ("%s", errstr);
+  return EXECUTION_FAILURE;
+}
+
+/* Perform the same operation as bind_variable, but with VALUE being a
+ * number, not a string. */
+static SHELL_VAR *
+bind_variable_number (name, value, flags)
+     const char *name;
+     long value;
+     int flags;
+{
+  char numstr[25];    /* String version of VALUE */
+
+  sprintf (numstr, "%ld", value);
+  return bind_variable (name, numstr, flags);
+}
+
+/* Perform the same operation as bind_array_variable, but with VALUE
+ * being a number, not a string. */
+static SHELL_VAR *
+bind_array_variable_number (name, ind, value, flags)
+     char *name;
+     arrayind_t ind;
+     long value;
+     int flags;
+{
+  char numstr[25];    /* String version of VALUE */
+
+  sprintf (numstr, "%ld", value);
+  return bind_array_variable (name, ind, numstr, flags);
+}
+
+/* Define a reduction-type function (allreduce, scan, exscan, etc.). */
+typedef int (*reduction_func_t)(void *, void *, int, MPI_Datatype, MPI_Op, MPI_Comm);
+
+/* Perform any reduction-type operation (allreduce, scan, exscan, etc.). */
+static int
+reduction_like (list, funcname, func)
+     WORD_LIST *list;
+     char *funcname;
+     reduction_func_t func;
+{
+  char *word;                   /* One argument */
+  struct {
+    long int value;             /* Reduced value */
+    int rank;                   /* Rank associated with the above */
+  } number, result;
+  MPI_Op operation = MPI_SUM;   /* Operation to perform */
+  char *varname;                /* Name of the variable to bind the results to */
+  intmax_t n;
+  int i;
+
+  /* Parse "-O OPERATION" (optional), where OPERATION is a reduction
+   * operation. */
+  YES_ARGS (list);
+  word = list->word->word;
+  if (ISOPTION (word, 'O'))
+    {
+      list = list->next;
+      if (list == 0)
+        {
+          sh_needarg (funcname);
+          return (EX_USAGE);
+        }
+      word = list->word->word;
+      if (!parse_operation (word, &operation))
+        {
+          sh_invalidopt ("-O");
+          return (EX_USAGE);
+        }
+      list = list->next;
+    }
+
+  /* Parse the argument, which must be a number. */
+  YES_ARGS (list);
+  word = list->word->word;
+  if (!legal_number (word, &n))
+    {
+      sh_neednumarg (funcname);
+      return (EX_USAGE);
+    }
+  number.value = (long int) n;
+  number.rank = mpi_rank;
+  list = list->next;
+
+  /* Parse the target variable, which must not be read-only. */
+  YES_ARGS (list);
+  varname = list->word->word;
+  if (mpi_rank != 0 || func != MPI_Exscan)
+    REQUIRE_WRITABLE (varname);
+  list = list->next;
+  no_args (list);
+
+  /* Perform the reduction operation.  Bind the given array variable
+   * to the result and, for minloc/maxloc, the associated rank. */
+  if (mpi_rank != 0 || func != MPI_Exscan) {
+    bind_array_variable (varname, 0, "", 0);
+    bind_array_variable (varname, 1, "", 0);
+  }
+  if (operation == MPI_MINLOC || operation == MPI_MAXLOC)
+    {
+      MPI_TRY (func (&number, &result, 1, MPI_LONG_INT, operation, MPI_COMM_WORLD));
+      if (mpi_rank != 0 || func != MPI_Exscan)
+	bind_array_variable_number (varname, 1, result.rank, 0);
+    }
+  else
+    MPI_TRY (func (&number.value, &result.value, 1, MPI_LONG, operation, MPI_COMM_WORLD));
+  if (mpi_rank != 0 || func != MPI_Exscan)
+    bind_array_variable_number (varname, 0, result.value, 0);
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN mpi_comm_rank
+$FUNCTION mpi_comm_rank_builtin
+$SHORT_DOC mpi_comm_rank name
+Return the process's rank in the MPI job.
+
+Arguments:
+  NAME          Scalar variable in which to receive the rank
+
+Exit Status:
+Returns 0 unless an invalid option is given.
+$END
+/*'*/
+
+/* Here is the mpi_comm_rank builtin. */
+int
+mpi_comm_rank_builtin (list)
+     WORD_LIST *list;
+{
+  char *varname;         /* Name of the variable to bind the results to */
+
+  YES_ARGS (list);
+  varname = list->word->word;
+  REQUIRE_WRITABLE (varname);
+  list = list->next;
+  no_args (list);
+  bind_variable_number (varname, mpi_rank, 0);
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN mpi_comm_size
+$FUNCTION mpi_comm_size_builtin
+$SHORT_DOC mpi_comm_size name
+Return the total number of ranks in the MPI job.
+
+Arguments:
+  NAME          Scalar variable in which to receive the number of ranks
+
+Exit Status:
+Returns 0 unless an invalid option is given.
+$END
+
+/* Here is the mpi_comm_size builtin. */
+int
+mpi_comm_size_builtin (list)
+     WORD_LIST *list;
+{
+  char *varname;         /* Name of the variable to bind the results to */
+
+  YES_ARGS (list);
+  varname = list->word->word;
+  REQUIRE_WRITABLE (varname);
+  list = list->next;
+  no_args (list);
+  bind_variable_number (varname, mpi_num_ranks, 0);
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN mpi_abort
+$FUNCTION mpi_abort_builtin
+$SHORT_DOC mpi_abort [n]
+Abort all processes in the MPI job and exit the shell.
+
+Exits not only the caller's shell (with a status of N) but also all
+remote shells that are part of the same MPI job.  If N is omitted, the
+exit status is that of the last command executed.
+
+This command should be used only in extreme circumstances.  It is
+better for each process to exit normally on its own.
+$END
+/*'*/
+
+/* Here is the mpi_abort builtin. */
+int
+mpi_abort_builtin (list)
+     WORD_LIST *list;
+{
+  int exit_value;
+
+  exit_value = (running_trap == 1 && list == 0) ? trap_saved_exit_value : get_exitstat (list);  /* Copied from exit.def */
+  MPI_TRY (MPI_Abort (MPI_COMM_WORLD, exit_value));
+  return EXECUTION_FAILURE;
+}
+
+$BUILTIN mpi_send
+$FUNCTION mpi_send_builtin
+$SHORT_DOC mpi_send [-t tag] rank message
+Send a message to a remote process in the same MPI job.
+
+Options:
+  -t TAG        Send the message using tag TAG (default: 0).  TAG must
+                be a nonnegative integer.
+
+Arguments:
+  RANK          Whom to send the message to.  RANK must be an integer in
+                the range [0, $(mpi_comm_size)-1].
+
+  MESSAGE       String to send to rank RANK.
+
+Exit Status:
+Returns 0 unless an invalid option is given or an error occurs.
+$END
+
+/* Here is the mpi_send builtin. */
+int
+mpi_send_builtin (list)
+     WORD_LIST *list;
+{
+  char *word;              /* One argument */
+  intmax_t target_rank;    /* MPI target rank */
+  char *message;           /* Message to send to rank target_rank */
+  intmax_t tag = 0;        /* Message tag to use */
+
+  /* Parse "-t TAG" (optional), where TAG is a number or "any". */
+  YES_ARGS (list);
+  word = list->word->word;
+  if (ISOPTION (word, 't'))
+    {
+      list = list->next;
+      if (list == 0)
+        {
+          sh_needarg ("mpi_recv");
+          return (EX_USAGE);
+        }
+      word = list->word->word;
+      if (!legal_number (word, &tag))
+        {
+          sh_neednumarg ("-t");
+          return (EX_USAGE);
+        }
+      list = list->next;
+    }
+  else if (*word == '-')
+    {
+      sh_invalidopt (word);
+      builtin_usage ();
+      return (EX_USAGE);
+    }
+
+  /* Parse the target rank, which must be a number. */
+  YES_ARGS (list);
+  word = list->word->word;
+  if (!legal_number (word, &target_rank))
+    {
+      builtin_error (_("mpi_send: numeric rank required"));
+      return (EX_USAGE);
+    }
+  list = list->next;
+
+  /* Parse the message to send. */
+  YES_ARGS (list);
+  message = list->word->word;
+  list = list->next;
+  no_args (list);
+
+  /* Send the message. */
+  MPI_TRY (MPI_Send (message, strlen(message)+1, MPI_BYTE, (int)target_rank, (int)tag, MPI_COMM_WORLD));
+  return EXECUTION_SUCCESS;
+}
+
+
+$BUILTIN mpi_recv
+$FUNCTION mpi_recv_builtin
+$SHORT_DOC mpi_recv [-t tag] rank name
+Receive a message from a remote process in the same MPI job.
+
+Options:
+  -t TAG        Receive only messages sent using tag TAG (default: 0).
+                TAG must be either a nonnegative integer or the string
+                "any" to receive messages sent using any tag.
+
+Arguments:
+  RANK          Receive only messages sent from sender RANK.  RANK
+                must either be in the range [0, $(mpi_comm_size)-1] or
+                be the string "any" to receive messages from any sender.
+
+  NAME          Array variable in which to receive the message, sender
+                rank, and tag.
+
+Exit Status:
+Returns 0 unless an invalid option is given or an error occurs.
+$END
+
+/* Here is the mpi_recv builtin. */
+int
+mpi_recv_builtin (list)
+     WORD_LIST *list;
+{
+  char *word;            /* One argument */
+  intmax_t source_rank;  /* MPI source rank */
+  char *endptr;          /* Used for parsing strings into numbers */
+  MPI_Status status;     /* Status of an MPI operation */
+  int count;             /* Message length in bytes */
+  intmax_t tag = 0;      /* Message tag to use */
+  char *varname;         /* Name of the variable to bind the results to */
+  static char *message = NULL;  /* Message received from MPI */
+  static size_t alloced = 0;    /* Number of bytes allocated for the above */
+  int opt;               /* Parsed option */
+
+  /* Parse any options provided. */
+  reset_internal_getopt ();
+  while ((opt = internal_getopt (list, "t:")) != -1)
+    {
+      switch (opt)
+        {
+          case 't':
+            if (!strcmp (list_optarg, "any"))
+              tag = MPI_ANY_TAG;
+            else if (!legal_number (list_optarg, &tag))
+              {
+                builtin_error (_("-t: numeric argument or \"any\" required"));
+                return (EX_USAGE);
+              }
+            break;
+
+          default:
+            sh_invalidopt (word);
+            builtin_usage ();
+            return (EX_USAGE);
+        }
+    }
+  list = loptend;
+
+  /* Parse the source rank, which must be a number or "any". */
+  YES_ARGS (list);
+  word = list->word->word;
+  if (!legal_number (word, &source_rank))
+    {
+      if (!strcmp (word, "any"))
+        source_rank = MPI_ANY_SOURCE;
+      else
+        {
+          builtin_error (_("mpi_recv: numeric rank or \"any\" required"));
+          return (EX_USAGE);
+        }
+    }
+  list = list->next;
+
+  /* Parse the target variable, which must not be read-only. */
+  YES_ARGS (list);
+  varname = list->word->word;
+  REQUIRE_WRITABLE (varname);
+  list = list->next;
+  no_args (list);
+
+  /* Receive a message.  Because we don't know long the message will
+   * be, we first probe to get the length. */
+  MPI_TRY (MPI_Probe ((int)source_rank, (int)tag, MPI_COMM_WORLD, &status));
+  MPI_TRY (MPI_Get_count (&status, MPI_BYTE, &count));
+  if (alloced < count)
+    {
+      message = xrealloc (message, count);
+      alloced = count;
+    }
+  MPI_TRY (MPI_Recv (message, count, MPI_BYTE, status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD, &status));
+  bind_array_variable (varname, 0, message, 0);
+  bind_array_variable_number (varname, 1, status.MPI_SOURCE, 0);
+  bind_array_variable_number (varname, 2, status.MPI_TAG, 0);
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN mpi_barrier
+$FUNCTION mpi_barrier_builtin
+$SHORT_DOC mpi_barrier
+Synchronizes all of the processes in the MPI job.
+
+No process will return from mpi_barrier until all processes have
+called mpi_barrier.
+
+Exit Status:
+Returns 0 unless an invalid option is given or an error occurs.
+$END
+
+/* Here is the mpi_barrier builtin. */
+int
+mpi_barrier_builtin (list)
+     WORD_LIST *list;
+{
+  no_args (list);
+  MPI_TRY (MPI_Barrier (MPI_COMM_WORLD));
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN mpi_bcast
+$FUNCTION mpi_bcast_builtin
+$SHORT_DOC mpi_bcast [message] name
+Broadcast a message to all processes in the same MPI job.
+
+Arguments:
+  MESSAGE       String to broadcast from one process to all the others.
+
+  NAME          Scalar variable in which to receive the broadcast message.
+
+Exactly one process in the MPI job must specify a message to
+broadcast.  No process will return from mpi_bcast until all processes
+have called mpi_bcast.
+
+Exit Status:
+Returns 0 unless an invalid option is given or an error occurs.
+$END
+
+/* Here is the mpi_bcast builtin. */
+int
+mpi_bcast_builtin (list)
+     WORD_LIST *list;
+{
+  char *word;            /* One argument */
+  int root;              /* MPI root rank */
+  char *root_message;    /* Message to broadcast */
+  int msglen;            /* Length in bytes of the above (including the NULL byte) */
+  char *varname;         /* Name of the variable to bind the results to */
+  static int *all_lengths = NULL;   /* List of every rank's msglen */
+  static char *message = NULL;      /* Message received from the root */
+  static int alloced = 0;           /* Bytes allocated for the above */
+  int i;
+
+  /* Parse the optional message and target variable, which must not be
+   * read-only. */
+  YES_ARGS (list);
+  if (list->next == NULL)
+    {
+      /* Non-root */
+      root_message = NULL;
+      msglen = -1;
+    }
+  else
+    {
+      /* Root */
+      root_message = list->word->word;
+      msglen = (int) strlen(root_message) + 1;
+      list = list->next;
+    }
+  varname = list->word->word;
+  REQUIRE_WRITABLE (varname);
+  list = list->next;
+  no_args (list);
+
+  /* Acquire global agreement on the root and the message size. */
+  if (all_lengths == NULL)
+    all_lengths = xmalloc (mpi_num_ranks*sizeof(int));
+  MPI_TRY (MPI_Allgather (&msglen, 1, MPI_INT, all_lengths, 1, MPI_INT, MPI_COMM_WORLD));
+  root = -1;
+  for (i = 0; i < mpi_num_ranks; i++)
+    {
+      if (all_lengths[i] == -1)
+        continue;
+      if (root != -1)
+        {
+          builtin_error (_("mpi_bcast: more than one process specified a message"));
+          return (EXECUTION_FAILURE);
+        }
+      root = i;
+      msglen = all_lengths[i];
+    }
+  if (root == -1)
+    {
+      builtin_error (_("mpi_bcast: no process specified a message"));
+      return (EXECUTION_FAILURE);
+    }
+
+  /* Broadcast the message. */
+  if (mpi_rank == root)
+    {
+      MPI_TRY (MPI_Bcast (root_message, msglen, MPI_BYTE, root, MPI_COMM_WORLD));
+      bind_variable (varname, root_message, 0);
+    }
+  else
+    {
+      if (alloced < msglen)
+        {
+          message = xrealloc (message, msglen);
+          alloced = msglen;
+        }
+      MPI_TRY (MPI_Bcast (message, msglen, MPI_BYTE, root, MPI_COMM_WORLD));
+      bind_variable (varname, message, 0);
+    }
+  return EXECUTION_SUCCESS;
+}
+
+$BUILTIN mpi_scan
+$FUNCTION mpi_scan_builtin
+$SHORT_DOC mpi_scan number name
+Perform an inclusive scan across all processes in the same MPI job.
+
+ -O OPERATION   Operation to perform.  Must be one of "max", "min",
+                "sum", "prod", "land", "band", "lor", "bor", "lxor",
+                "bxor", "maxloc", or "minloc" (default: "sum").
+
+Arguments:
+  NUMBER        Integer to use in the scan operation.
+
+  NAME          Array variable in which to receive the result and, in
+                the case of maxloc and minloc, the associated rank.
+
+In an inclusive-scan operation, each process i presents a number,
+a[i].  Once all processes in the MPI job have presented their number,
+the command returns a[0] to rank 0, a[0]+a[1] to rank 1,
+a[0]+a[1]+a[2] to rank 2, and so forth.  The -O option enables "+" to
+be replaced with other operations.
+
+Inclusive scans can be useful for assigning a unique index to each
+process in the MPI job.
+
+Exit Status:
+Returns 0 unless an invalid option is given or an error occurs.
+$END
+
+/* Here is the mpi_scan builtin. */
+int
+mpi_scan_builtin (list)
+     WORD_LIST *list;
+{
+  return reduction_like (list, "mpi_scan", MPI_Scan);
+}
+
+$BUILTIN mpi_exscan
+$FUNCTION mpi_exscan_builtin
+$SHORT_DOC mpi_exscan number name
+Perform an exclusive scan across all processes in the same MPI job.
+
+ -O OPERATION   Operation to perform.  Must be one of "max", "min",
+                "sum", "prod", "land", "band", "lor", "bor", "lxor",
+                "bxor", "maxloc", or "minloc" (default: "sum").
+
+Arguments:
+  NUMBER        Integer to use in the scan operation.
+
+  NAME          Array variable in which to receive the result and, in
+                the case of maxloc and minloc, the associated rank.
+
+In a exclusive-scan operation, each process i presents a number, a[i].
+Once all processes in the MPI job have presented their number, the
+command assigns a[0] to NAME on rank 1, a[0]+a[1] to NAME on rank 2,
+a[0]+a[1]+a[2] to NAME on rank 3, and so forth.  No assignment is
+performed on rank 0.  The -O option enables "+" to be replaced with
+other operations.
+
+Exclusive scans can be useful for assigning a unique index to each
+process in the MPI job.
+
+Exit Status:
+Returns 0 unless an invalid option is given or an error occurs.
+$END
+
+/* Here is the mpi_exscan builtin. */
+int
+mpi_exscan_builtin (list)
+     WORD_LIST *list;
+{
+  return reduction_like (list, "mpi_exscan", MPI_Exscan);
+}
+
+$BUILTIN mpi_allreduce
+$FUNCTION mpi_allreduce_builtin
+$SHORT_DOC mpi_allreduce number name
+Reduce numbers from all processes in an MPI job to a single number.
+
+Options:
+
+ -O OPERATION   Operation to perform.  Must be one of "max", "min",
+                "sum", "prod", "land", "band", "lor", "bor", "lxor",
+                "bxor", "maxloc", or "minloc" (default: "sum").
+
+Arguments:
+  NUMBER        Integer to use in the allreduce operation.
+
+  NAME          Array variable in which to receive the result and, in
+                the case of maxloc and minloc, the associated rank.
+
+In an all-reduce operation, each process i presents a number, a[i].
+Once all processes in the MPI job have presented their number, the
+command returns a[0]+a[1]+...+a[n-1] to all ranks.  The -O option
+enables "+" to be replaced with other operations.
+
+All-reduces can be useful for reaching global agreement (e.g., of a
+termination condition).
+
+Exit Status:
+Returns 0 unless an invalid option is given or an error occurs.
+$END
+
+/* Here is the mpi_allreduce builtin. */
+int
+mpi_allreduce_builtin (list)
+     WORD_LIST *list;
+{
+  return reduction_like (list, "mpi_allreduce", MPI_Allreduce);
+}
diff -Naur bash-4.3/config.h.in mpibash-4.3/config.h.in
--- bash-4.3/config.h.in	2013-06-29 15:35:33.000000000 -0600
+++ mpibash-4.3/config.h.in	2014-05-13 11:27:37.314100671 -0600
@@ -1147,6 +1147,12 @@
 /* Define if you have the `__argz_stringify' function. */
 #undef HAVE___ARGZ_STRINGIFY
 
+/* Define if you have both the <libcircle.h> header file and the libcircle library. */
+#undef HAVE_LIBCIRCLE
+
+/* Define if you have the `CIRCLE_cb_reduce_op' function. */
+#undef HAVE_CIRCLE_CB_REDUCE_OP
+
 /* End additions for lib/intl */
 
 #include "config-bot.h"
diff -Naur bash-4.3/configure.ac mpibash-4.3/configure.ac
--- bash-4.3/configure.ac	2014-02-11 08:37:53.000000000 -0700
+++ mpibash-4.3/configure.ac	2014-05-13 11:27:37.302100179 -0600
@@ -24,7 +24,7 @@
 AC_REVISION([for Bash 4.3, version 4.063])dnl
 
 define(bashvers, 4.3)
-define(relstatus, release)
+define(relstatus, MPI)
 
 AC_INIT([bash], bashvers-relstatus, [bug-bash@gnu.org])
 
@@ -813,6 +813,21 @@
     fi
 ])
 
+dnl Ensure that we can find an MPI library.
+AC_CHECK_FUNCS([MPI_Init], [], [
+  AC_MSG_ERROR([Cannot continue without MPI.  Consider specifying CC=mpicc.])])
+
+dnl If we have Libcircle, use it, too.
+AC_SEARCH_LIBS([CIRCLE_cb_create], [circle], [AC_CHECK_HEADERS([libcircle.h])])
+if test "x$ac_cv_header_libcircle_h" = xyes; then
+  libcircle_make_prefix=""
+  AC_DEFINE([HAVE_LIBCIRCLE], [1], [Define if you have the Libcircle header and library.])
+  AC_CHECK_FUNCS([CIRCLE_cb_reduce_op])
+else
+  libcircle_make_prefix="#"
+fi
+AC_SUBST([CIRCLE], [$libcircle_make_prefix])
+
 BASH_CHECK_DECL(strtoimax)
 BASH_CHECK_DECL(strtol)
 BASH_CHECK_DECL(strtoll)
diff -Naur bash-4.3/Makefile.in mpibash-4.3/Makefile.in
--- bash-4.3/Makefile.in	2014-01-25 14:27:30.000000000 -0700
+++ mpibash-4.3/Makefile.in	2014-05-13 11:27:37.314100671 -0600
@@ -104,7 +104,7 @@
 VERSPROG = bashversion$(EXEEXT)
 VERSOBJ = bashversion.$(OBJEXT)
 
-Program = bash$(EXEEXT)
+Program = mpibash$(EXEEXT)
 Version = @BASHVERS@
 PatchLevel = `$(BUILD_DIR)/$(VERSPROG) -p`
 RELSTATUS = @RELSTATUS@
diff -Naur bash-4.3/shell.c mpibash-4.3/shell.c
--- bash-4.3/shell.c	2014-01-14 06:04:32.000000000 -0700
+++ mpibash-4.3/shell.c	2014-05-13 11:27:37.314100671 -0600
@@ -107,6 +107,13 @@
 extern char *primary_prompt, *secondary_prompt;
 extern char *this_command_name;
 
+extern void initialize_mpi __P((int, char **));
+extern void finalize_mpi __P((void));
+#ifdef HAVE_LIBCIRCLE
+extern void initialize_libcircle __P((int, char **));
+extern void finalize_libcircle __P((void));
+#endif
+
 /* Non-zero means that this shell has already been run; i.e. you should
    call shell_reinitialize () if you need to start afresh. */
 int shell_initialized = 0;
@@ -324,7 +331,7 @@
 static void init_interactive_script __P((void));
 
 static void set_shell_name __P((char *));
-static void shell_initialize __P((void));
+static void shell_initialize __P((int, char **));
 static void shell_reinitialize __P((void));
 
 static void show_shell_usage __P((FILE *, int));
@@ -561,7 +568,7 @@
 
   /* From here on in, the shell must be a normal functioning shell.
      Variables from the environment are expected to be set, etc. */
-  shell_initialize ();
+  shell_initialize (argc, argv);
 
   set_default_lang ();
   set_default_locale_vars ();
@@ -941,6 +948,12 @@
     end_job_control ();
 #endif /* JOB_CONTROL */
 
+#ifdef HAVE_LIBCIRCLE
+  finalize_libcircle ();
+#else
+  finalize_mpi ();
+#endif
+
   /* Always return the exit status of the last command to our parent. */
   sh_exit (s);
 }
@@ -1691,7 +1704,9 @@
 /* Do whatever is necessary to initialize the shell.
    Put new initializations in here. */
 static void
-shell_initialize ()
+shell_initialize (argc, argv)
+     int argc;
+     char **argv;
 {
   char hostname[256];
 
@@ -1760,6 +1775,17 @@
   initialize_shell_options (privileged_mode||running_setuid);
   initialize_bashopts (privileged_mode||running_setuid);
 #endif
+
+  /* Initialize Libcircle and MPI. */
+#ifdef HAVE_LIBCIRCLE
+  initialize_libcircle (argc, argv);
+  initialize_mpi (argc, argv);
+  bind_variable ("libcircle", "yes", 0);
+#else
+  initialize_mpi (argc, argv);
+  bind_variable ("libcircle", "no", 0);
+#endif
+  bind_variable ("mpibash", "yes", 0);
 }
 
 /* Function called by main () when it appears that the shell has already