Skip to content

Commit c4af527

Browse files
committed
把main函数中拆解read得到kmer的代码进行更改,拆解出的kmer需要使用0作为结尾
1 parent 9fabbc4 commit c4af527

10 files changed

+103
-68
lines changed

communicator.cpp

+17-13
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,28 @@ requestOtherRanksToStoreVertex(int currank, int world_size, VertexId vertexId, E
145145
}
146146

147147
// 该方法负责char *指针的delete
148+
// TODO: 不负责read的delete
148149
int processRecvRead(const char *filename, size_t pos) {
149150
ifstream infile(filename);
150-
string read;
151+
string *read = new string;
151152
infile.seekg(pos);
152-
getline(infile, read);
153+
getline(infile, *read);
153154
infile.close();
154-
delete filename;
155-
if (requestWriteRead(read) == 0) return 0;
155+
delete[] filename;
156+
if (requestWriteRead(*read) == 0) return 0;
156157
return 1;
157158
}
158159

159160
// 该方法负责char *指针的delete
160161
int processRecvEdge(EdgeList *edgeList, char *value, ReadId readId, KMERPOS_t kmerpos) {
161-
string strValue(string(value, 0, getK()));
162-
163-
VertexId sourceVertex = getId(strValue.substr(0, strValue.size()-1));
164-
VertexId sinkVertex = getId(strValue.substr(1, strValue.size()-1));
162+
string *strValue = new string(value, 0, getK()-1);
163+
VertexId sourceVertex = getId(*strValue);
164+
delete strValue;
165+
strValue = new string(value, 1, getK()-1);
166+
VertexId sinkVertex = getId(*strValue);
167+
delete strValue;
165168
int flag = addNewEdge(edgeList, value, sourceVertex, sinkVertex, readId, kmerpos);
166-
delete value;
169+
delete[] value;
167170
return flag;
168171
}
169172

@@ -175,7 +178,7 @@ int processRecvVertex(VertexList *vertexList, SetOfID *tangleList, VertexId vert
175178
flag = addVertex(vertexList, vertexId, edgeId, 0, vertexMode);
176179

177180
if (MULTI_OUT_DEGREE == (flag & MULTI_OUT_DEGREE)) {
178-
tangleList->safe_insert(vertexId);
181+
//tangleList->safe_insert(vertexId);
179182
}
180183
return flag;
181184
}
@@ -275,11 +278,12 @@ void *receiverRunner(void *args) {
275278
char *kmer = nullptr;
276279
ReadId readId;
277280
MPI_Unpack(pack, packSize, &position, &strLen, 1, MPI_INT, MPI_COMM_WORLD);
278-
kmer = new char[strLen];
281+
kmer = new char[strLen+1];
279282
if (strLen != getK()) {
280283
cout << "Trasmission error: " << strLen << endl;
281284
}
282285
MPI_Unpack(pack, packSize, &position, kmer, strLen, MPI_CHAR, MPI_COMM_WORLD);
286+
kmer[strLen] = '\0';
283287
MPI_Unpack(pack, packSize, &position, &readId, 1, my_MPI_SIZE_T, MPI_COMM_WORLD);
284288
KMERPOS_t kmerpos;
285289
MPI_Unpack(pack, packSize, &position, &kmerpos, 1, MPI_UNSIGNED, MPI_COMM_WORLD);
@@ -394,14 +398,14 @@ item::item() {
394398
}
395399

396400
// 不能与线程并行的共存
397-
void sendSuperContigToRankHead(int headrank, int currank, string superContig) {
401+
void sendSuperContigToRankHead(int headrank, int currank, string &superContig) {
398402
int msgsize = superContig.size();
399403
MPI_Send(&msgsize, 1, MPI_INT, headrank, TAG(currank, headrank), MPI_COMM_WORLD);
400404
MPI_Send(superContig.c_str(), superContig.size(), MPI_CHAR, headrank, TAG(currank, headrank), MPI_COMM_WORLD);
401405
}
402406

403407
// 不能与线程并行的共存
404-
string reduceSuperContigFromOthers(int currank, int world_size, string superContig) {
408+
string reduceSuperContigFromOthers(int currank, int world_size, string &superContig) {
405409
stringstream sc;
406410
sc << superContig;
407411
//cout << superContig;

communicator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ void *testReceiverRunner(void *arg);
100100

101101
void *receiverRunner(void *recvArg);
102102

103-
void sendSuperContigToRankHead(int headrank, int currank, string superContig);
103+
void sendSuperContigToRankHead(int headrank, int currank, string &superContig);
104104

105-
string reduceSuperContigFromOthers(int currank, int world_size, string superContig);
105+
string reduceSuperContigFromOthers(int currank, int world_size, string &superContig);
106106

107107
int queryEdgeById(string *pEdgeStr, int currank, int tarrank, EdgeId edgeId);
108108

entity/idset.h

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inline size_t getId(const std::string& value) {
1414
return std::hash<std::string>()(value);
1515
}
1616

17+
inline size_t getId(const char *value) {
18+
return std::hash<std::string>()(value);
19+
}
20+
1721
//typedef std::unordered_set<size_t> SetOfID;
1822
typedef size_t ReadId;
1923
typedef size_t VertexId;

entity/k_mer.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ int addNewEdge(EdgeList *eList, char *value, VertexId sourceVId, VertexId sinkVI
6969

7070
int
7171
addNewEdge(EdgeList *eList, char *value, EdgeId *fetchedEdgeId, VertexId sourceVId, VertexId sinkVId, ReadId rId, KMERPOS_t kmerpos) {
72-
string idStr(value, 0, getK());
73-
EdgeId eId = hash<string>()(idStr);
72+
EdgeId eId = hash<string>()(value);
7473
Edge *e = nullptr;
7574
pthread_mutex_lock(&kmerMutex);
7675
if (eList->find(eId) == eList->end()) {
@@ -86,7 +85,9 @@ addNewEdge(EdgeList *eList, char *value, EdgeId *fetchedEdgeId, VertexId sourceV
8685
return 0;
8786
}
8887
// cout << string(value, 0, getK()).c_str() << endl;
89-
strcpy(e->value, string(value, 0, getK()).c_str());
88+
for (int i = 0; i < getK(); ++i) {
89+
e->value[i] = value[i];
90+
}
9091

9192
e->sourceKMinusMerId = sourceVId;
9293
e->sinkKMinusMerId = sinkVId;

entity/k_mer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "idset.h"
1010
#include "read.h"
11-
#include <unordered_map>
11+
#include <map>
1212

1313
struct kMer {
1414
size_t id;
@@ -31,7 +31,7 @@ struct kMer {
3131

3232
typedef struct kMer Edge;
3333
typedef struct kMer KMer;
34-
typedef std::unordered_map<EdgeId , Edge *> EdgeList;
34+
typedef std::map<EdgeId , Edge *> EdgeList;
3535
typedef EdgeList KMerList;
3636

3737
void setK(int k);

entity/k_minus_mer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ unsigned int addVertex(VertexList *vList, char *value, const EdgeId inKMerId, co
1818

1919
unsigned int addVertex(VertexList *vList, char *value, VertexId *fetchedVertexId, const EdgeId inKMerId,
2020
const EdgeId outKMerId, VertexMode_t mode) {
21-
string idStr(string(value, 0, getK()-1));
22-
VertexId vId = hash<string>()(idStr);
21+
VertexId vId = hash<string>()(value);
2322
if (nullptr != fetchedVertexId) {
2423
*fetchedVertexId = vId;
2524
}

entity/k_minus_mer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define RANDOMSTRINGASSEMBLY_K_MINUS_MER_H
77

88
#include "idset.h"
9-
#include <unordered_map>
9+
#include <map>
1010

1111
// Constants for VertexMode_t
1212
#define HEAD_VERTEX 1u
@@ -34,7 +34,7 @@ struct kMinusMer {
3434

3535
typedef struct kMinusMer Vertex;
3636
typedef struct kMinusMer KMinusMer;
37-
typedef std::unordered_map<VertexId, Vertex *> VertexList;
37+
typedef std::map<VertexId, Vertex *> VertexList;
3838

3939
typedef unsigned int VertexMode_t;
4040
//typedef int VertexAddReturn_t;

0 commit comments

Comments
 (0)