-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpcudadef.cpp
More file actions
184 lines (149 loc) · 5.83 KB
/
pcudadef.cpp
File metadata and controls
184 lines (149 loc) · 5.83 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
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
/*
Pcuda: Simulating P systems with active membranes on the GPU
This simulator is published on:
J.M. Cecilia, J.M. García, G.D. Guerrero, M.A. Martínez-del-Amor, I. Pérez-Hurtado,
M.J. Pérez-Jiménez. Simulation of P systems with active membranes on CUDA,
Briefings in Bioinformatics, 11, 3 (2010), 313-322
Pcuda is a subproject of PMCGPU (Parallel simulators for Membrane
Computing on the GPU)
Copyright (c) 2009 Miguel Á. Martínez-del-Amor (RGNC, University of Seville)
Ginés D. Guerrero (GACOP, University of Murcia)
Chema Cecilia (GACOP, University of Murcia)
Ignacio Pérez-Hurtado (RGNC, University of Seville)
This file is part of Pcuda.
Pcuda is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pcuda is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pcuda. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#include <iostream>
#include "pcudadef.h"
using namespace std;
/***********************/
/* AUXILIARY FUNCTIONS */
int select_skin (Configuration *cfg, Pcuda_configuration pcfg) {
int mult=0;
Rulelist * rulelist=NULL;
Rule * rule=NULL;
bool rule_end=false;
cfg->new_selection();
rulelist=cfg->get_rules()->get_rulelist(pcfg->skin_label,pcfg->skin_charge);
rulelist->start_iteration();
while (!rulelist->end() && !rule_end) {
rule=rulelist->next_rule();
if (rule==NULL) break;
/* [ a --> U ] */
if ((rule->type == RULE_EVOLUTION) && (pcfg->skin_multiset[rule->a]>0 )) {
mult=pcfg->skin_multiset[rule->a];
pcfg->skin_multiset[rule->a]=0;
if (mult>0)
cfg->get_selection()->add_selected_rule(rule,cfg->get_skin(),mult);
}
/* [a] --> b[] */
else if ((rule->type == RULE_SEND_OUT) && (pcfg->skin_multiset[rule->a]>0 )) {
mult=pcfg->skin_multiset[rule->a];
if (mult>0) {
pcfg->skin_multiset[rule->a]--;
cfg->get_selection()->add_selected_rule(rule,cfg->get_skin(),1);
rule_end=true;
}
}
}
return cfg->get_selection()->get_length();
}
int execute_skin (Configuration *cfg, Pcuda_configuration pcfg) {
Rule* rule=NULL;
int count=0,num_exec=0;
if (cfg==NULL||pcfg==NULL) return -1;
cfg->get_selection()->start_iteration();
while (!cfg->get_selection()->end() ) {
rule=cfg->get_selection()->get_rule();
count=cfg->get_selection()->get_times();
cfg->get_selection()->next_selection();
switch (rule->type) {
case RULE_EVOLUTION: /* [ a --> U ] */
rule->new_multiset->add_to_array(pcfg->skin_multiset,pcfg->skinmultiset_len,count);
num_exec++;
break;
case RULE_SEND_OUT:
pcfg->environment[rule->b]++;
pcfg->skin_charge=rule->new_charge;
num_exec++;
break;
}
}
cfg->delete_selection();
return num_exec;
}
void print_multisets(Configuration * cfg, Pcuda_configuration pcfg, Problem_size ps) {
uint num_objects=ps->num_objects;
string out;
char convert[50];
cout << "***********************************" << endl << "MULTISETS: " << endl;
for (int i=0;i<pcfg->max_num_membranes;i++) {
if (pcfg->membraneset[i].label==EMPTY_MEMBRANE) continue;
cout << "MEMBRANE ID: " << i << ", Label: " << pcfg->membraneset[i].label << ", Charge: " << pcfg->membraneset[i].charge << endl;
cout << "Multiset: ";
out = "";
/* For each element in the multiset */
for (int j=0; j < num_objects; j++) {
if (pcfg->multisets[i*num_objects+j]>0) {
/*sprintf(convert,"%d",j);
out+=convert;*/
out+=cfg->get_alphabet()[j];
if (pcfg->multisets[i*num_objects+j]>1) {
out+="*";
sprintf(convert,"%d",pcfg->multisets[i*num_objects+j]);
out+=convert;
}
out+=", ";
}
}
cout << out << endl;
}
cout << endl;
}
void print_skin(Configuration * cfg, Pcuda_configuration pcfg, Problem_size ps) {
uint num_objects=ps->num_objects;
string out;
char convert[50];
cout << "***********************************" << endl << "SKIN:" << endl;
out="";
for (int j=0; j < num_objects; j++) {
if (pcfg->skin_multiset[j]>0) {
out+=cfg->get_alphabet()[j];
if (pcfg->skin_multiset[j]>1) {
out+="*";
sprintf(convert,"%d",pcfg->skin_multiset[j]);
out+=convert;
}
out+=", ";
}
}
cout << out << endl;
}
void print_environment(Configuration * cfg, Pcuda_configuration pcfg, Problem_size ps) {
uint num_objects=ps->num_objects;
string out;
char convert[50];
cout << "***********************************" << endl << "ENVIRONMENT" << endl;
out="";
for (uint j=0; j < num_objects; j++) {
if (pcfg->environment[j]>0) {
out+=cfg->get_alphabet()[j];
if (pcfg->environment[j]>1) {
out+="*";
sprintf(convert,"%d",pcfg->environment[j]);
out+=convert;
}
out+=", ";
}
}
cout << out ;
}