-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparfu_data_transfer.cc
2010 lines (1765 loc) · 76.8 KB
/
parfu_data_transfer.cc
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
////////////////////////////////////////////////////////////////////////////////
//
// University of Illinois/NCSA Open Source License
// http://otm.illinois.edu/disclose-protect/illinois-open-source-license
//
// Parfu is copyright © 2017, The Trustees of the University of Illinois.
// All rights reserved.
//
// Parfu was developed by:
// The University of Illinois
// The National Center For Supercomputing Applications (NCSA)
// Blue Waters Science and Engineering Applications Support Team (SEAS)
// Craig P Steffen <csteffen@ncsa.illinois.edu>
//
// https://github.com/ncsa/parfu_archive_tool
// http://www.ncsa.illinois.edu/People/csteffen/parfu/
//
// For full licnse text see the LICENSE file provided with the source
// distribution.
//
////////////////////////////////////////////////////////////////////////////////
#include "parfu_primary.h"
#include "tarentry.hh"
// this is an MPI function; expected to be run by all ranks.
// we assume that each rank can allocate, fill, and use a buffer
// the size of a whole bucket.
// This function takes the original (unsplit) list as input. It's assumed
// to be sorted and combined in the right way; the files are ordered as they
// are supposed to be.
// This function splits the list along the way, then broadcasts the split
// lists to the ranks for transferring.
// blocking_size is the size that all files are blocked up to by reserving
// room. This will mostly be the same as the blocking size for tar files,
// which as of this writing we generally assume is 512 bytes. Since this
// size is tied with interoperability with tar, this will generally be
// fixed at compile-time.
// Bucket size is how much data each rank of parfu operates on. Files are
// blocked together to fill up that size. If files are larger than that,
// they're split across multiple buckets and data is moved by multiple
// ranks.
// max_files_per_bucket is a limit to the number of individual files in
// a bucket. If files are super-small, the ranks that read the individual
// files from disk and push that data into the archive file may end up
// incurring unreasonable amount of latency to do so. This limit can be
// set to limit this effect; the downside is that more space is
// wasted in the archive file.
extern "C"
void parfu_print_MPI_error(FILE *target,
int error_number){
char MPI_error_msg[MPI_MAX_ERROR_STRING];
int return_length;
MPI_Error_string(error_number, MPI_error_msg, &return_length);
fprintf(target,"MPI error string: >%s<\n",MPI_error_msg);
return;
}
extern "C"
int parfu_wtar_archive_list_to_singeFP(parfu_file_fragment_entry_list_t *myl,
int n_ranks, int my_rank,
long int blocking_size,
long int bucket_size,
int max_files_per_bucket,
char *archive_file_name){
int debug=0;
MPI_File *archive_file_ptr=NULL;
MPI_Info my_Info=MPI_INFO_NULL;
long int data_offset;
int number_of_rank_buckets;
char *padding_filename=NULL;
char *arch_file_catalog_buffer=NULL;
long int arch_file_catalog_buffer_length;
long int arch_file_catalog_buffer_length_w_tar_header;
char *split_list_catalog_buffer=NULL;
long int split_list_catalog_buffer_length=0;
char *shared_split_list_catalog_buffer=NULL;
char *catalog_tar_header_buffer=NULL;
parfu_file_fragment_entry_list_t *my_split_list=NULL;
parfu_file_fragment_entry_list_t *shared_split_list=NULL;
char *shared_archive_file_name=NULL;
int archive_filename_length;
int file_result;
int catalog_takes_n_buckets;
int catalog_tar_entry_size;
int return_bucket_size;
int *rank_call_list=NULL;
int *shared_rank_call_list=NULL;
int rank_call_list_length;
MPI_Status my_MPI_Status;
int i;
if(debug)
fprintf(stderr," *** data move 00\n");
if((padding_filename=(char*)malloc(sizeof(char)*(strlen(PARFU_BLOCKING_FILE_NAME)+1)))
==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr,"could not allocate space for pad file name.\n");
return 101;
}
sprintf(padding_filename,"%s",PARFU_BLOCKING_FILE_NAME);
// extract the archive (in file) catalog
// this will be written to the archive file on disk
if(my_rank==0){
if((arch_file_catalog_buffer=
parfu_fragment_list_to_buffer(myl,&arch_file_catalog_buffer_length,
bucket_size,1))
==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," could not write catalog to buffer\n");
return 103;
}
if(archive_file_name==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," rank 0 archive_file_name == NULL!!\n");
return 104;
}
if((archive_filename_length=strlen(archive_file_name))<1){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," archive filename length = %d!!\n",archive_filename_length);
return 105;
}
}
if(debug)
fprintf(stderr," *** data move 01\n");
MPI_Bcast(&archive_filename_length,1,MPI_INT,0,MPI_COMM_WORLD);
// distribute the archive file name to all ranks so it can be collectively open()-ed
if((shared_archive_file_name=(char*)malloc(archive_filename_length+1))==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," could not archive shared buffer for archive name!!\n");
return 106;
}
if(my_rank==0){
sprintf(shared_archive_file_name,"%s",archive_file_name);
if(debug)
fprintf(stderr," arch filename debug: >%s< >%s<\n",
archive_file_name,shared_archive_file_name);
}
MPI_Bcast(shared_archive_file_name,archive_filename_length+1,MPI_CHAR,0,MPI_COMM_WORLD);
// open the archive file on all ranks with a shared pointer
if(debug)
fprintf(stderr," *** data move 02\n");
// allocate a pointer to the archive file on every rank
if((archive_file_ptr=(MPI_File*)malloc(sizeof(MPI_File)))==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr,"rank %d could not allocate space for archive file pointer!\n",my_rank);
MPI_Finalize();
return 75;
}
if(my_rank==0)
fprintf(stderr,"about to open archive file on all ranks.\n");
if(debug)
fprintf(stderr," *** data move 03\n");
// every rank collectively opens the archive file so everyone can write to it
file_result=MPI_File_open(MPI_COMM_WORLD, shared_archive_file_name,
MPI_MODE_WRONLY | MPI_MODE_CREATE ,
my_Info, archive_file_ptr);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr,"MPI_File_open for archive buffer: returned error! error=%d Rank %d file >%s<\n",
file_result,
my_rank,
archive_file_name);
parfu_print_MPI_error(stderr,file_result);
return 3;
}
if(debug)
fprintf(stderr," *** data move 04, file open on all ranks.\n");
// the shared archive file is open, rank 0 writes the catalog to it
if(my_rank==0){
catalog_tar_entry_size =
tarentry::compute_hdr_size(PARFU_CATALOG_FILE_NAME,"",arch_file_catalog_buffer_length);
if((catalog_tar_header_buffer=(char*)malloc(catalog_tar_entry_size))==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," couldn not allocate catalog_tar_header_buffer!\n");
return 9;
}
parfu_construct_tar_header_for_catalog(catalog_tar_header_buffer,
arch_file_catalog_buffer_length);
file_result=MPI_File_write_at(*archive_file_ptr,
0, // tar header for catalog goes at beginning of file
catalog_tar_header_buffer,
catalog_tar_entry_size,
MPI_CHAR,&my_MPI_Status);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr,"rank 0 got %d from MPI_File_write_at_all\n",file_result);
fprintf(stderr," trying to write catalog tar header at location zero\n");
parfu_print_MPI_error(stderr,file_result);
MPI_Finalize();
return 169;
}
fprintf(stderr,"rank 0 about to write data catalog to archive file.\n");
file_result=MPI_File_write_at(*archive_file_ptr,
catalog_tar_entry_size, // write catalog just AFTER its tar header
arch_file_catalog_buffer,
arch_file_catalog_buffer_length,
MPI_CHAR,&my_MPI_Status);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr,"rank 0 got %d from MPI_File_write_at_all\n",file_result);
fprintf(stderr," trying to write catalog of size %ld at location %d\n",
arch_file_catalog_buffer_length,catalog_tar_entry_size);
parfu_print_MPI_error(stderr,file_result);
MPI_Finalize();
return 160;
}
// create tar header for parfu catalog
}
// calculate and distribute data offset
if(my_rank==0){
int loc_of_end_of_catalog;
int space_between_catalog_and_data;
int loc_of_tar_header_for_spacing;
int spacer_file_size;
arch_file_catalog_buffer_length_w_tar_header =
arch_file_catalog_buffer_length + catalog_tar_entry_size;
catalog_takes_n_buckets = arch_file_catalog_buffer_length_w_tar_header / bucket_size;
if( arch_file_catalog_buffer_length_w_tar_header % bucket_size )
catalog_takes_n_buckets++;
data_offset = catalog_takes_n_buckets * bucket_size;
loc_of_end_of_catalog
= catalog_tar_entry_size + arch_file_catalog_buffer_length;
space_between_catalog_and_data = data_offset - loc_of_end_of_catalog;
if(space_between_catalog_and_data > blocking_size){
// then we need to put in a tar header to fill in the gap between
// the end of the catalog and the beginning of the main data block
loc_of_tar_header_for_spacing = loc_of_end_of_catalog;
if(loc_of_end_of_catalog % blocking_size){
// if the end of the catalog isn't on a block boundary, push it
// exactly to the next one
loc_of_tar_header_for_spacing +=
(blocking_size - (loc_of_end_of_catalog % blocking_size));
}
spacer_file_size =
(data_offset - loc_of_tar_header_for_spacing)
- catalog_tar_entry_size;
parfu_construct_tar_header_for_space(catalog_tar_header_buffer,
spacer_file_size);
file_result=MPI_File_write_at(*archive_file_ptr,
loc_of_tar_header_for_spacing,
catalog_tar_header_buffer,
catalog_tar_entry_size,
MPI_CHAR,&my_MPI_Status);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr,"rank 0 got %d from MPI_File_write_at_all\n",file_result);
fprintf(stderr," trying to write tar_header for post-catalog file.\n");
parfu_print_MPI_error(stderr,file_result);
MPI_Finalize();
return 169;
}
} // if(space_between_catalog_and_data...
} // if(my_rank==0....
// broadcast the data offset within the archive file. All ranks will use this
// as the start of the data payload section of the archive file.
MPI_Bcast(&data_offset,1,MPI_LONG_INT,0,MPI_COMM_WORLD);
if(debug)
fprintf(stderr," *** data move 05\n");
// split file list and distribute results to all ranks
if(my_rank==0){
FILE *dumpfile=NULL;
int size_written;
if((my_split_list=parfu_set_offsets_and_split_ffel(myl,blocking_size,
bucket_size,
padding_filename,
&number_of_rank_buckets,
-1 // indicating no max files per bucket
))
==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," error from parfu_set_offsets_and_split_ffel() !!!\n");
return 102;
}
if((split_list_catalog_buffer=
parfu_fragment_list_to_buffer(my_split_list,&split_list_catalog_buffer_length,
bucket_size,0))
==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," could not write catalog to buffer\n");
return 103;
}
// dump list for debugging
if(debug){
if((dumpfile=fopen("parfu_dump_split_list.txt","w"))==NULL){
fprintf(stderr,"Rank ZERO cannot open dump file. Aborting!\n");
exit(111);
}
size_written=
fwrite(split_list_catalog_buffer,sizeof(char),split_list_catalog_buffer_length,dumpfile);
if(size_written != split_list_catalog_buffer_length){
fprintf(stderr,"WARNING! Could not write whole dump file!\n");
}
fclose(dumpfile);
dumpfile=NULL;
}
if((rank_call_list=
parfu_rank_call_list_from_ffel(my_split_list,&rank_call_list_length))
==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," error from parfu_rank_call_list_from_ffel!!\n");
return 104;
}
// check rank call list
fprintf(stderr,"Rank zero checking the rank call list for validity\n");
for(i=0;i<rank_call_list_length;i++){
if( i != my_split_list->list[rank_call_list[i]].rank_bucket_index ){
fprintf(stderr,"something is VERY VERY WRONG. Rank call list has an error!\n");
fprintf(stderr," i = %d, corredponding split list entry rank_bucket_index=%d!\n",
i,my_split_list->list[rank_call_list[i]].rank_bucket_index);
return(666);
}
} // for(i=0;
fprintf(stderr,"rank_call_list checks out. All good to go!\n");
}
MPI_Bcast(&split_list_catalog_buffer_length,1,MPI_LONG_INT,0,MPI_COMM_WORLD);
if(debug)
fprintf(stderr," *** data move 06\n");
if((shared_split_list_catalog_buffer=(char*)malloc(split_list_catalog_buffer_length))==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," could not allocate split_list buffer! rank %d\n",my_rank);
return 76;
}
if(my_rank==0)
memcpy(shared_split_list_catalog_buffer,split_list_catalog_buffer,split_list_catalog_buffer_length);
MPI_Bcast(shared_split_list_catalog_buffer,split_list_catalog_buffer_length,MPI_CHAR,0,MPI_COMM_WORLD);
if(debug)
fprintf(stderr," *** data move 07\n");
if((shared_split_list=
parfu_buffer_to_file_fragment_list(shared_split_list_catalog_buffer,
&return_bucket_size,0))==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr,"rank %d could not create split list!!\n",my_rank);
return 78;
}
if(debug)
fprintf(stderr," *** data move 08\n");
MPI_Bcast(&rank_call_list_length,1,MPI_INT,0,MPI_COMM_WORLD);
if((shared_rank_call_list=(int*)malloc(sizeof(int)*rank_call_list_length))
==NULL){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," rank %d can't allocate shared_rank_call_list!!\n",my_rank);
return 79;
}
if(my_rank==0)
memcpy(shared_rank_call_list,rank_call_list,rank_call_list_length*sizeof(int));
MPI_Bcast(shared_rank_call_list,rank_call_list_length,MPI_INT,0,MPI_COMM_WORLD);
// fprintf(stderr," *** data move 09 rcll=%d rank=%d\n",rank_call_list_length,my_rank);
// all ranks have their own list, and valid file pointers, and the call list
if(my_rank==0){
fprintf(stderr,"rank 0 debugging\n");
fprintf(stderr," original list length: %d\n",myl->n_entries_full);
fprintf(stderr," split list length: %d\n",shared_split_list->n_entries_full);
// fprintf(stderr,"dumping rank call list: endpoint=%d\n",
// shared_split_list->n_entries_full);
// for(i=0;i<rank_call_list_length;i++){
// fprintf(stderr," i=%05d bucket_beginning_index=%05d\n",
// i,rank_call_list[i]);
// }
}
// all the ranks now check their own rank call list
if(debug){
MPI_Barrier(MPI_COMM_WORLD);
fprintf(stderr,"rank %d call list length: %d\n",my_rank,rank_call_list_length);
MPI_Barrier(MPI_COMM_WORLD);
fprintf(stderr,"rank %d first rank value: %d\n",my_rank,shared_rank_call_list[0]);
MPI_Barrier(MPI_COMM_WORLD);
fprintf(stderr,"rank %d first rank value: %d\n",my_rank,shared_rank_call_list[rank_call_list_length-1]);
MPI_Barrier(MPI_COMM_WORLD);
}
for(i=0;i<rank_call_list_length;i++){
if( i != shared_split_list->list[shared_rank_call_list[i]].rank_bucket_index ){
fprintf(stderr,"rank=%d parfu_wtar_archive_list_to_singeFP:\n",my_rank);
fprintf(stderr,"rank=%d something is VERY VERY WRONG. Shared rank call list has an error!\n",my_rank);
fprintf(stderr,"rank=%d i = %d, corredponding split list entry rank_bucket_index=%d!\n",
my_rank,i,shared_split_list->list[shared_rank_call_list[i]].rank_bucket_index);
return(666);
}
} // for(i=0;
if(debug)
fprintf(stderr,"rank %d finished with list\n",my_rank);
MPI_Barrier(MPI_COMM_WORLD);
if(my_rank==0){
fprintf(stderr,"rank 0: all ranks finished shared_rank_call_list check.\n");
fprintf(stderr," proceeding to call parfu_wtar_archive_allbuckets_singFP()\n");
}
if((file_result=parfu_wtar_archive_allbuckets_singFP(shared_split_list,
n_ranks,my_rank,
shared_rank_call_list,
rank_call_list_length,
blocking_size,
bucket_size,
data_offset,
archive_file_ptr))!=0){
fprintf(stderr,"parfu_wtar_archive_list_to_singeFP:\n");
fprintf(stderr," rank %d got error %d from parfu_wtar_archive_allbuckets_singFP()!\n",
my_rank,file_result);
return 88;
}
return 0;
}
extern "C"
int parfu_wtar_archive_allbuckets_singFP(parfu_file_fragment_entry_list_t *myl,
int n_ranks, int my_rank,
int *rank_call_list,
int rank_call_list_length,
long int blocking_size,
long int bucket_size,
long int data_region_start,
MPI_File *archive_file_ptr){
int data_index;
int data_index_start;
int data_index_end;
// MPI_Info my_Info=MPI_INFO_NULL;
int return_val;
// int file_result;
int rank_iter;
void *transfer_buffer=NULL;
if(archive_file_ptr==NULL){
fprintf(stderr,"parfu_wtar_archive_allbuckets_singFP:\n");
fprintf(stderr," help! archive_file_ptr is NULL!!\n");
return 2;
}
if((transfer_buffer=malloc(bucket_size))==NULL){
fprintf(stderr,"parfu_wtar_archive_allbuckets_singFP:\n");
fprintf(stderr," could not allocate transfer buffer!\n");
return 3;
}
memset(transfer_buffer,'\0',bucket_size);
if(rank_call_list==NULL){
fprintf(stderr,"parfu_wtar_archive_allbuckets_singFP:\n");
fprintf(stderr," We received a rank_call_list that was NULL!!\n");
return 7;
}
/*
if((archive_file_ptr=(MPI_File*)malloc(sizeof(MPI_File)))==NULL){
fprintf(stderr,"parfu_wtar_archive_allbuckets_singFP:\n");
fprintf(stderr,"rank %d could not allocate space for archive file pointer!\n",my_rank);
MPI_Finalize();
return 75;
}
file_result=MPI_File_open(MPI_COMM_WORLD, archive_file_name,
MPI_MODE_WRONLY | MPI_MODE_CREATE | MPI_MODE_EXCL,
my_Info, archive_file_ptr);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"parfu_wtar_archive_allbuckets_singFP:\n");
fprintf(stderr,"parfu_archive_1file_singFP:\n");
fprintf(stderr,"MPI_File_open for archive buffer: returned error! Rank %d file >%s<\n",
my_rank,
archive_file_name);
return 3;
}
*/
rank_iter = my_rank;
// fprintf(stderr," @@@ rank %5d about to enter loop of _one_bucket calls\n",
// my_rank);
if(my_rank==0)
fprintf(stderr,"Rank 0: all ranks about to iterate over the rank buckets!\n");
while(rank_iter < rank_call_list_length){
// all the ranks now check their own rank call list (again)
if( myl->list[rank_call_list[rank_iter]].rank_bucket_index != rank_iter ){
fprintf(stderr," rank=%d parfu_wtar_archive_allbuckets_singFP:\n",my_rank);
fprintf(stderr," mismatch about to call parfu_wtar_archive_one_bucket_singFP!\n");
fprintf(stderr," rank_iter = %d myl->list[rank_call_list[rank_iter]].rank_bucket_index=%d\n",
rank_iter,
myl->list[rank_call_list[rank_iter]].rank_bucket_index);
return(667);
}
if((return_val=parfu_wtar_archive_one_bucket_singFP(myl,n_ranks,my_rank,
rank_call_list,
rank_iter,
blocking_size,bucket_size,
transfer_buffer,
data_region_start,
archive_file_ptr))){
fprintf(stderr,"parfu_wtar_archive_allbuckets_singFP:\n");
fprintf(stderr,"rank_iter=%d\n",rank_iter);
fprintf(stderr," received value %d from parfu_wtar_archive_one_bucket_singFP. Help!\n",
return_val);
data_index = rank_call_list[rank_iter];
data_index_start = data_index - 5;
data_index_end = data_index + 5;
if(data_index_start < 0)
data_index_start = 0;
if(data_index_end > myl->n_entries_full)
data_index_end = myl->n_entries_full - 1;
for(data_index=data_index_start;data_index<data_index_end;data_index++){
fprintf(stderr," rank=%d loc=%ld bucket=%d file=%s\n",
my_rank,
myl->list[data_index].location_in_archive_file,
myl->list[data_index].rank_bucket_index,
myl->list[data_index].relative_filename);
}
return 12;
}
rank_iter += n_ranks;
} // while(rank_iter < ...
fprintf(stderr," &&& rank %d exiting all buckets loop at rank iter %d\n",
my_rank,rank_iter);
return 0;
}
extern "C"
int parfu_wtar_archive_one_bucket_singFP(parfu_file_fragment_entry_list_t *myl,
int n_ranks, int my_rank,
int *rank_call_list,
int rank_call_list_index,
long int blocking_size,
long int bucket_size,
void *transfer_buffer,
long int data_region_start,
MPI_File *archive_file_ptr){
int current_entry;
int last_bucket_index;
// long int source_file_loc;
long int archive_file_loc;
long int current_bucket_loc;
long int current_write_loc_in_bucket;
long int blocked_data_written;
// long int total_blocked_data_written;
long int data_offset_in_buffer;
// long int pad_file_location_in_bucket;
MPI_File *target_file_ptr_ptr=NULL;
MPI_Info my_Info=MPI_INFO_NULL;
MPI_Status my_MPI_Status;
std::vector<char> temp_file_header_C;
tarentry my_tar_header_C;
int file_result;
int local_pad_file_size;
int pad_space;
// int remainder;
int i;
int terminator_length=1024;
if(bucket_size < 10000){
fprintf(stderr,"parfu_wtar_archive_one_bucket_singFP:\n");
fprintf(stderr," Input bucket_size is: %ld !!!\n",bucket_size);
fprintf(stderr," this is very unlikely to be right!\n");
return 100;
}
if(transfer_buffer == NULL){
fprintf(stderr,"parfu_wtar_archive_one_bucket_singFP:\n");
fprintf(stderr," transfer buffer is NULL!\n");
return 101;
}
if((target_file_ptr_ptr=(MPI_File*)malloc(sizeof(MPI_File)))==NULL){
fprintf(stderr,"parfu_wtar_archive_one_bucket_singFP:\n");
fprintf(stderr,"could not allocate target_file_ptr_ptr!!\n");
return 102;
}
current_entry=rank_call_list[rank_call_list_index];
last_bucket_index = myl->list[current_entry].rank_bucket_index;
if( myl->list[rank_call_list[rank_call_list_index]].rank_bucket_index !=
rank_call_list_index ){
fprintf(stderr,"rank=%d parfu_wtar_archive_one_bucket_singFP: !help\n",my_rank);
fprintf(stderr,"rank=%d rank_call_list_index=%d myl[[]].rank_bucket_index=%d !\n",
my_rank,rank_call_list_index,
myl->list[rank_call_list[rank_call_list_index]].rank_bucket_index);
return 668;
}
// copy data from file(s) into buffer
// walk through entries until we hit the next bucket
current_bucket_loc =
bucket_size * ((long int)(rank_call_list_index));
current_write_loc_in_bucket = 0L;
// total_blocked_data_written=0L;
// fprintf(stderr," ^^^ rank %d beginning single bucket while loop\n",my_rank);
// fprintf(stderr,"CCC_1 rank=%5d index=%5d\n",my_rank,rank_call_list_index);
while( current_entry < myl->n_entries_full &&
myl->list[current_entry].rank_bucket_index == last_bucket_index ){
// open target file
// fprintf(stderr," @@@ rank %d opening file > %s <\n",
// my_rank,
// myl->list[current_entry].relative_filename);
// we only need to open and read from files that are
// actual files and have non-zero size
if( ( myl->list[current_entry].type == PARFU_FILE_TYPE_REGULAR ) &&
( myl->list[current_entry].our_file_size > 0 ) ){
file_result=MPI_File_open(MPI_COMM_SELF,
myl->list[current_entry].relative_filename,
MPI_MODE_RDONLY,
my_Info,target_file_ptr_ptr);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"parfu_wtar_archive_one_bucket_singFP:\n");
fprintf(stderr,"rank %d got non-zero result when opening target file >%s<!\n",
my_rank,
myl->list[current_entry].relative_filename);
fprintf(stderr,"for reading. result=%d\n",file_result);
parfu_print_MPI_error(stderr,file_result);
return 138;
}
// fprintf(stderr," ??? rank %5d has opened
// copy data from target file to buffer
// file_result=
// MPI_File_read_at(target_file_ptr,
// myl->list[current_entry].location_in_orig_file,
// ((void*)(((char*)(transfer_buffer)+current_write_loc_in_bucket))),
// myl->list[current_entry].our_file_size,
// MPI_CHAR,&my_MPI_Status);
data_offset_in_buffer=
myl->list[current_entry].location_in_archive_file-
current_bucket_loc;
if(data_offset_in_buffer < 0 ||
data_offset_in_buffer >= bucket_size){
int artificial_index;
//
fprintf(stderr,"parfu_wtar_archive_one_bucket_singFP: rank %d\n",my_rank);
fprintf(stderr," rank %d has data_offset_in_buffer=%ld which is outside buffer! index=%d\n",
my_rank,data_offset_in_buffer,current_entry);
fprintf(stderr," rank %d rank_call_list_index=%d last_bucket_index=%d rank_call_list entry=%d\n",
my_rank,
rank_call_list_index,
last_bucket_index,
rank_call_list[rank_call_list_index]);
fprintf(stderr," rank %d datasz=%ld bucketsize=%ld bucket_index=%d filename=>%s<\n",my_rank,
myl->list[current_entry].our_file_size,
bucket_size,
myl->list[current_entry].rank_bucket_index,
myl->list[current_entry].relative_filename);
fprintf(stderr," rank %d current_bucket_loc: %ld\n",
my_rank,current_bucket_loc);
artificial_index=current_entry-4;
if(artificial_index >= 0)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry-3;
if(artificial_index >= 0)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry-2;
if(artificial_index >= 0)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry-1;
if(artificial_index >= 0)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry;
if(artificial_index >= 0)
fprintf(stderr," rank %d indx=%d (PROB) datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry+1;
if(artificial_index < myl->n_entries_full)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry+2;
if(artificial_index < myl->n_entries_full)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry+3;
if(artificial_index < myl->n_entries_full)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
artificial_index=current_entry+4;
if(artificial_index < myl->n_entries_full)
fprintf(stderr," rank %d indx=%d datasz=%ld bucket_index=%d loc: %ld filename=>%s<\n",my_rank,
artificial_index,
myl->list[artificial_index].our_file_size,
myl->list[artificial_index].rank_bucket_index,
myl->list[artificial_index].location_in_archive_file,
myl->list[artificial_index].relative_filename);
return 149;
}
file_result=
MPI_File_read_at(*target_file_ptr_ptr,
myl->list[current_entry].location_in_orig_file,
(void*)(((char*)(transfer_buffer)+
(myl->list[current_entry].location_in_archive_file-
current_bucket_loc))),
myl->list[current_entry].our_file_size,
MPI_CHAR,&my_MPI_Status);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"parfu_wtar_archive_one_bucket_singFP:\n");
fprintf(stderr,"rank %d got %d from MPI_File_read_at\n",my_rank,file_result);
fprintf(stderr,"reading fragment %d",rank_call_list_index);
fprintf(stderr,"file %s\n",myl->list[current_entry].relative_filename);
parfu_print_MPI_error(stderr,file_result);
fprintf(stderr,"YY:r=%d,OF=%ld,SZ=%ld,FN=>%s<\n",
my_rank,myl->list[current_entry].location_in_orig_file,myl->list[current_entry].our_file_size,
myl->list[current_entry].relative_filename);
return 159;
}
} // if it's a real file with data
// create the tar header for this file, if it's the first chunk of the file
if(!(myl->list[current_entry].location_in_orig_file)){
my_tar_header_C = tarentry(myl->list[current_entry].relative_filename,0);
temp_file_header_C = my_tar_header_C.make_tar_header();
std::copy(temp_file_header_C.begin(), temp_file_header_C.end(),
((((char*)(transfer_buffer))+
((myl->list[current_entry].location_in_archive_file -
current_bucket_loc)
- myl->list[current_entry].our_tar_header_size)
)));
}
// accounting for data written to archive file
blocked_data_written =
(myl->list[current_entry].our_file_size >= 0 ? myl->list[current_entry].our_file_size : 0);
if(!(myl->list[current_entry].location_in_orig_file)){
blocked_data_written += myl->list[current_entry].our_tar_header_size;
}
if( blocked_data_written % blocking_size ){
blocked_data_written =
( (blocked_data_written / blocking_size) + 1) * blocking_size;
}
current_write_loc_in_bucket += blocked_data_written;
//
current_entry++;
MPI_File_close(target_file_ptr_ptr);
} // while(myl->list[current_entry].rank_bucket_index == ....
free(target_file_ptr_ptr);
target_file_ptr_ptr=NULL;
// now check to see if we need to add a tar header at the end to pad space
// from the end of our data to the beginning of the next bucket
pad_space = bucket_size-current_write_loc_in_bucket;
if( (pad_space - blocking_size) >= 0 ){
//write a tar header to bridge the gap to the next bucket
local_pad_file_size = pad_space - blocking_size;
parfu_construct_tar_header_for_space( ((char*)(transfer_buffer))+
current_write_loc_in_bucket,
local_pad_file_size);
/* my_tar_header_C = tarentry(".parfu_spacer",0);
temp_file_header_C = my_tar_header_C.make_tar_header();
std::copy(temp_file_header_C.begin(), temp_file_header_C.end(),
((((char*)(transfer_buffer))+
current_write_loc_in_bucket)));*/
// we're assuming here the tar header is the blocking size
// not guaranteed but in practice is always true.
current_write_loc_in_bucket += blocking_size;
}
/*
if( current_entry < myl->n_entries_full ){
// if we're not at the end of the list
// we look at first entry of the NEXT rank to see if it needs a pad
// in our section. If it has a name, then there's an entry.
if(myl->list[current_entry].pad_file_archive_filename != NULL){
// pad_file_location_in_bucket =
// myl->list[current_entry].pad_file_location_in_archive_file -
// current_bucket_loc;
// if(pad_file_location_in_bucket < 0 ||
// pad_file_location_in_bucket >= bucket_size){
// fprintf(stderr," HELP HELP!! spaceer tar headre outside buffer!!! rank=%5d ; %ld\n",
// my_rank,pad_file_location_in_bucket);
// }
// parfu_construct_tar_header_for_space( ((char*)(transfer_buffer))+
// pad_file_location_in_bucket,
//
//myl->list[current_entry].pad_file_size);
if(
parfu_construct_tar_header_for_space( ((char*)(transfer_buffer))+
current_write_loc_in_bucket,
myl->list[current_entry].pad_file_size);
}
} */
// fprintf(stderr," ### rank %d copied data to buffer. Now moving to archive file.\n",my_rank);
// fprintf(stderr,"CCC_2 rank=%5d index=%5d\n",my_rank,rank_call_list_index);
// now copy the whole buffer to the archive file
archive_file_loc = data_region_start +
(rank_call_list_index * bucket_size);
/* file_result=MPI_File_write_at_all(*archive_file_ptr,
archive_file_loc,
transfer_buffer,
current_write_loc_in_bucket,
MPI_CHAR,&my_MPI_Status);*/
file_result=MPI_File_write_at(*archive_file_ptr,
archive_file_loc,
transfer_buffer,
current_write_loc_in_bucket, // size of transfer
MPI_CHAR,&my_MPI_Status);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"rank %d got %d from MPI_File_write_at_all\n",my_rank,file_result);
fprintf(stderr,"archive_file_loc: %ld\n",archive_file_loc);
fprintf(stderr,"bytes to move: %ld\n",current_write_loc_in_bucket);
fprintf(stderr,"writing slice %d\n",rank_call_list_index);
parfu_print_MPI_error(stderr,file_result);
MPI_Finalize();
return 160;
}
if(current_entry == myl->n_entries_full){
// if((remainder=(current_write_loc_in_bucket % blocking_size))){
// current_write_loc_in_bucket +=
// (blocking_size - remainder);
for(i=0;i<terminator_length;i++){
sprintf( ((char*)(transfer_buffer))+i,"%c",'\0');
}
archive_file_loc = data_region_start +
((rank_call_list_index+1) * bucket_size);
file_result=MPI_File_write_at(*archive_file_ptr,
archive_file_loc,
transfer_buffer,
terminator_length,
MPI_CHAR,&my_MPI_Status);
if(file_result != MPI_SUCCESS){
fprintf(stderr,"rank %d got %d from MPI_File_write_at_all\n",my_rank,file_result);
fprintf(stderr," writing tar file terminator block.\n");
parfu_print_MPI_error(stderr,file_result);
MPI_Finalize();
return 160;
}
// } // if(remainder==(current_write_loc_in_bucket....
} // if(current_entry == ...
// if we're the very very last transfer in the archive file, pad the file out to
// the block size to make tar happy.
// fprintf(stderr,"CCC_3 rank=%5d index=%5d\n",my_rank,rank_call_list_index);
return 0;
}
/*
extern "C"
int parfu_archive_1file_singFP(parfu_file_fragment_entry_list_t *raw_list,
char *arch_file_name,
int n_ranks, int my_rank,
int my_max_block_size_exponent,
long int transfer_buffer_size,
int my_blocks_per_fragment,
int check_if_already_exist){
// the assumption of this function is that MPI stuff has already been
// initialized. The inputs for n_ranks and my_ranks are valid for all
// ranks; the others may only be valid for rank 0.
int filename_length;
char *archive_filename_buffer=NULL;
MPI_File *archive_file_MPI=NULL;
char *catalog_buffer_for_ranks=NULL;
long int rank0_catalog_buffer_for_ranks_length;
long int catalog_buffer_for_ranks_length;
char *catalog_buffer_for_archive=NULL;
long int catalog_buffer_for_archive_length;
MPI_File target_file_ptr;
// split list on rank 0 before broadcasting to all the ranks
parfu_file_fragment_entry_list_t *split_list=NULL;
// local-to-rank list from broadcast catalog
parfu_file_fragment_entry_list_t *rank_list=NULL;
int data_starting_position;
int max_block_size;
int archive_catalog_takes_n_blocks;
int crosscheck_max_block_size_exponent;
int current_target_fragment;
int rank0_current_target_fragment;
long int bytes_to_move;
void *transfer_buffer=NULL;
long int stage_bytes_left_to_move;
long int stage_target_file_offset;
long int stage_archive_file_offset;
long int file_block_size;
long int times_through_loop;
long int loop_divisor=100;
MPI_Info my_Info=MPI_INFO_NULL;
MPI_Status my_MPI_Status;
int file_result;
char *file_catalog_distributed=NULL;
// char *file_catalog_buffer_for_ranks=NULL;
// int target_fragment_increment;
time_t *local_start=NULL,*local_end=NULL;
int local_started=0;
if((transfer_buffer=(char*)malloc(transfer_buffer_size))==NULL){
fprintf(stderr,"parfu_archive_1file_singFP:\n");
fprintf(stderr," could not allocate transfer buffer of size %ld bytes\n",
transfer_buffer_size);
return 99;