This source file includes following definitions.
- mca_sharedfp_individual_insert_metadata
- mca_sharedfp_individual_write_metadata_file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include "ompi_config.h"
22 #include "sharedfp_individual.h"
23
24 #include "mpi.h"
25 #include "ompi/constants.h"
26 #include "ompi/mca/sharedfp/sharedfp.h"
27 #include "ompi/mca/sharedfp/base/base.h"
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include "mpi.h"
32
33 int mca_sharedfp_individual_insert_metadata(int functype,long recordlength,struct mca_sharedfp_base_data_t *sh )
34 {
35 int ret = OMPI_SUCCESS;
36 mca_sharedfp_individual_metadata_node *newnode = NULL;
37 mca_sharedfp_individual_metadata_node *tempnode = NULL;
38 mca_sharedfp_individual_header_record *headnode = NULL;
39
40 headnode = (mca_sharedfp_individual_header_record*)sh->selected_module_data;
41 if ( NULL == headnode) {
42 opal_output (0, "sharedfp_individual_insert_metadat: headnode is NULL but file is open\n");
43 return OMPI_ERROR;
44 }
45
46
47 if ( mca_sharedfp_individual_verbose ) {
48 opal_output(ompi_sharedfp_base_framework.framework_output,
49 "sharedfp_individual_insert_metadata: Headnode->numofrecords = %d\n",
50 headnode->numofrecords);
51 }
52
53 if (headnode->numofrecords == MAX_METADATA_RECORDS) {
54
55 ret = mca_sharedfp_individual_write_metadata_file(sh);
56 headnode->next = NULL;
57 }
58
59
60 newnode = (mca_sharedfp_individual_metadata_node*)malloc(sizeof(mca_sharedfp_individual_metadata_node));
61 if (NULL == newnode) {
62 opal_output(0,"mca_sharedfp_individual_insert_metadata:Error while allocating new node\n");
63 return OMPI_ERR_OUT_OF_RESOURCE;
64 }
65
66
67
68 headnode->numofrecords = headnode->numofrecords + 1;
69
70 newnode->recordid = functype;
71 newnode->timestamp = mca_sharedfp_individual_gettime();
72 newnode->localposition = headnode->datafile_offset;
73 newnode->recordlength = recordlength;
74 newnode->next = NULL;
75
76
77 if ( headnode->next == NULL) {
78
79 headnode->next = newnode;
80 }
81 else {
82
83 tempnode = headnode->next;
84
85 while(tempnode->next) {
86 tempnode = tempnode->next;
87 }
88
89 tempnode->next = newnode;
90 }
91
92 return ret;
93 }
94
95 int mca_sharedfp_individual_write_metadata_file(struct mca_sharedfp_base_data_t *sh)
96 {
97 mca_sharedfp_individual_metadata_node *current = NULL;
98 struct mca_sharedfp_individual_record2 buff;
99 mca_sharedfp_individual_header_record *headnode = NULL;
100 int ret=OMPI_SUCCESS;
101 MPI_Status status;
102
103 headnode = (mca_sharedfp_individual_header_record*)sh->selected_module_data;
104
105 if (headnode->numofrecordsonfile == 0)
106 headnode->metadatafile_offset = headnode->metafile_start_offset;
107
108 current = headnode->next;
109 while (current != NULL) {
110
111
112 buff.recordid = current->recordid;
113 buff.timestamp = current->timestamp;
114 buff.localposition = current->localposition;
115 buff.recordlength = current->recordlength;
116
117 if ( mca_sharedfp_individual_verbose ) {
118 opal_output(ompi_sharedfp_base_framework.framework_output,
119 "sharedfp_individual_write_metadata_file: Buff recordid %ld\n",buff.recordid);
120 opal_output(ompi_sharedfp_base_framework.framework_output,
121 "sharedfp_individual_write_metadata_file: Buff timestamp %f\n", buff.timestamp);
122 opal_output(ompi_sharedfp_base_framework.framework_output,
123 "sharedfp_individual_write_metadata_file: Buff localposition %lld\n",buff.localposition);
124 opal_output(ompi_sharedfp_base_framework.framework_output,
125 "sharedfp_individual_write_metadata_file: Buff recordlength %ld\n",buff.recordlength);
126 opal_output(ompi_sharedfp_base_framework.framework_output,
127 "sharedfp_individual_write_metadata_file: Size of buff %ld\n",sizeof(buff));
128 }
129
130 headnode->next = current->next;
131 free(current);
132 current = (headnode)->next;
133
134
135
136 ret = mca_common_ompio_file_write_at ( (headnode)->metadatafilehandle,
137 (headnode)->metadatafile_offset,
138 &buff,32, MPI_BYTE, &status);
139 if ( OMPI_SUCCESS != ret ) {
140 goto exit;
141 }
142 (headnode)->numofrecordsonfile = headnode->numofrecordsonfile + 1;
143 (headnode)->metadatafile_offset = (headnode)->metadatafile_offset + sizeof(buff);
144 }
145
146
147 (headnode)->numofrecords = 0;
148
149 exit:
150 return ret;
151 }