-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtmp.c
More file actions
69 lines (61 loc) · 2.79 KB
/
tmp.c
File metadata and controls
69 lines (61 loc) · 2.79 KB
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
int write_lime_contraction(double * const s, char * filename, const int prec, const int N, char * type, const int gid, const int sid) {
MPI_File * ifs = NULL;
LemonWriter * writer = NULL;
LemonRecordHeader * header = NULL;
int status = 0;
int ME_flag=0, MB_flag=0;
n_uint64_t bytes;
DML_Checksum checksum;
char *message;
if(g_cart_id == 0) fprintf(stdout, "\n# [write_lime_contraction] constructing lemon writer for file %s\n", filename);
ifs = (MPI_File*)malloc(sizeof(MPI_File));
status = MPI_File_open(g_cart_grid, filename, MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, ifs);
if(status == MPI_SUCCESS) status = MPI_File_set_size(*ifs, 0);
status = (status == MPI_SUCCESS) ? 0 : 1;
writer = lemonCreateWriter(ifs, g_cart_grid);
status = status || (writer == NULL);
if(status) {
fprintf(stderr, "[write_lime_contraction] Error, could not open file for writing\n");
MPI_Abort(MPI_COMM_WORLD, 120);
MPI_Finalize();
exit(120);
}
// format message
message = (char*)malloc(2048);
sprintf(message, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cvcFormat>\n<type>%s</type>\n<precision>%d</precision>\n<components>%d</components>\n<lx>%d</lx>\n<ly>%d</ly>\n<lz>%d</lz>\n<lt>%d</lt>\n<nconf>%d</nconf>\n<source>%d</source>\n</cvcFormat>\ndate %s", type, prec, N, LX*g_nproc_x, LY*g_nproc_y, LZ*g_nproc_z, T_global, gid, sid, ctime(&g_the_time));
bytes = strlen(message);
MB_flag=1, ME_flag=1;
header = lemonCreateHeader(MB_flag, ME_flag, "cvc_contraction-format", bytes);
status = lemonWriteRecordHeader(header, writer);
lemonDestroyHeader(header);
lemonWriteRecordData( message, &bytes, writer);
lemonWriterCloseRecord(writer);
free(message);
// binary data message
bytes = (n_uint64_t)LX_global * LY_global * LZ_global * T_global * (n_uint64_t) (2*N*sizeof(double) * prec / 64);
MB_flag=1, ME_flag=0;
header = lemonCreateHeader(MB_flag, ME_flag, "scidac-binary-data", bytes);
status = lemonWriteRecordHeader(header, writer);
lemonDestroyHeader(header);
write_binary_contraction_data(s, writer, prec, N, &checksum);
// checksum message
message = (char*)malloc(512);
sprintf(message, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<scidacChecksum>\n"
" <version>1.0</version>\n"
" <suma>%08x</suma>\n"
" <sumb>%08x</sumb>\n"
"</scidacChecksum>", checksum.suma, checksum.sumb);
bytes = strlen(message);
MB_flag=0, ME_flag=1;
header = lemonCreateHeader(MB_flag, ME_flag, "scidac-checksum", bytes);
status = lemonWriteRecordHeader(header, writer);
lemonDestroyHeader(header);
lemonWriteRecordData( message, &bytes, writer);
lemonWriterCloseRecord(writer);
free(message);
lemonDestroyWriter(writer);
MPI_File_close(ifs);
free(ifs);
return(0);
}