Files
VisualSapfor/src/_VisualDVM/ProjectData/SapforData/Regions/ParallelRegion.java

151 lines
6.3 KiB
Java
Raw Normal View History

2024-10-09 22:21:57 +03:00
package _VisualDVM.ProjectData.SapforData.Regions;
import Common.Database.Objects.DBObject;
2023-09-17 22:13:42 +03:00
import Common.Utils.Index;
2025-05-10 17:15:45 +03:00
import Common.Utils.IntegerPairJson;
import Common.Utils.Pair;
2024-10-14 15:19:13 +03:00
import Common.Utils.Utils_;
import _VisualDVM.Global;
2024-10-09 22:21:57 +03:00
import _VisualDVM.ProjectData.Files.DBProjectFile;
import _VisualDVM.ProjectData.SapforData.Arrays.Distribution.AlignRule;
import _VisualDVM.ProjectData.SapforData.Arrays.Distribution.DataDirective;
import _VisualDVM.ProjectData.SapforData.Arrays.ProjectArray;
2025-05-10 17:15:45 +03:00
import com.google.gson.annotations.Expose;
2023-09-17 22:13:42 +03:00
import java.math.BigInteger;
import java.util.LinkedHashMap;
2025-05-10 17:15:45 +03:00
import java.util.List;
2023-09-17 22:13:42 +03:00
import java.util.Vector;
public class ParallelRegion extends DBObject {
2025-05-10 17:15:45 +03:00
//json
@Expose
public String packed_region_id;
@Expose
public String originalName;
@Expose
public List<ProjectArray> arrays=new Vector<>();
@Expose
public RegionLinesJson packed_lines;
//--
2023-09-17 22:13:42 +03:00
public BigInteger regionId;
//name in program
2025-05-10 17:15:45 +03:00
2023-09-17 22:13:42 +03:00
// file -> <start, end> lines
2025-05-10 17:15:45 +03:00
public LinkedHashMap<String, List<IntegerPairJson>> lines;
2023-09-17 22:13:42 +03:00
//ключ - адрес. меняем
2025-05-10 17:15:45 +03:00
public LinkedHashMap<BigInteger, ProjectArray> arraysMap;
2023-09-17 22:13:42 +03:00
//for directive creating
public DataDirective dataDirectives;
public int maxdim = 0;
public Vector<String> fragments = new Vector<>();
public int lines_count = 0;
public int loops_count = 0;
public int arrays_count = 0;
public int fd_count = 0;
public int fc_count = 0;
public ParallelRegion(String[] splited, Index idx) {
2025-05-10 17:15:45 +03:00
regionId = new BigInteger(splited[idx.Inc()]);//+
originalName = splited[idx.Inc()];//+
2023-09-17 22:13:42 +03:00
String[] localSplited = splited[idx.Inc()].split("\\|");
int lines_size = Integer.parseInt(localSplited[0]);
lines = new LinkedHashMap<>(lines_size);
//распаковка Lines -----------------------------------------------
//---------------------------------------------------------------
for (int i = 0; i < lines_size; ++i) {
2024-10-11 00:00:30 +03:00
String line_file = Utils_.toW(localSplited[1]);
2023-09-17 22:13:42 +03:00
int line_list_size = Integer.parseInt(localSplited[2]);
2025-05-10 17:15:45 +03:00
Vector<IntegerPairJson> current_lines = new Vector<>(line_list_size);
2023-09-17 22:13:42 +03:00
for (int k = 0; k < line_list_size; ++k) {
int first = Integer.parseInt(splited[idx.Inc()]);
if (first == 0) first++;
localSplited = splited[idx.Inc()].split("\\|");
int second = Integer.parseInt((localSplited[0]));
2025-05-10 17:15:45 +03:00
current_lines.add(new IntegerPairJson(first, second));
2023-09-17 22:13:42 +03:00
fragments.add(line_file + ": " + first + "-" + second);
}
lines.put(line_file, current_lines);
}
maxdim = 0;
int arrays_size = Integer.parseInt(splited[idx.Inc()]);
2025-05-10 17:15:45 +03:00
arraysMap = new LinkedHashMap<>(arrays_size);
2023-09-17 22:13:42 +03:00
for (int i = 0; i < arrays_size; ++i) {
BigInteger array_address = new BigInteger((splited[idx.Inc()]));
ProjectArray new_array = new ProjectArray(splited, idx, array_address);
2025-05-10 17:15:45 +03:00
arraysMap.put(array_address, new_array);
2023-09-17 22:13:42 +03:00
//-------------------------------------------------------
if (new_array.isTemplFlag == 1) {
maxdim = Math.max(maxdim, new_array.dimSize);
Global.mainModule.getProject().templates.add(new_array);
2023-09-17 22:13:42 +03:00
new_array.regIDs.add(regionId);
} else if (new_array.isLoopArrayFlag != 1) arrays_count++;
}
int dataDirectives_alignRules_size = Integer.parseInt(splited[idx.Inc()]);
dataDirectives = new DataDirective();
dataDirectives.alignRules = new Vector<>(dataDirectives_alignRules_size);
for (int i = 0; i < dataDirectives_alignRules_size; ++i)
dataDirectives.alignRules.add(new AlignRule(splited, idx));
for (int i = 0; i < dataDirectives.alignRules.size(); ++i)
dataDirectives.alignRules.get(i).parent_region = this;
//--------------------------------------------------------------
lines_count = 0;
loops_count = 0;
fd_count = 0;
fc_count = 0;
for (String FKey : lines.keySet()) {
2025-05-10 17:15:45 +03:00
for (IntegerPairJson L : lines.get(FKey)) {
2023-09-17 22:13:42 +03:00
lines_count += (L.getValue() - L.getKey());
DBProjectFile f = Global.mainModule.getProject().db.files.Data.get(FKey);
2023-09-17 22:13:42 +03:00
loops_count += f.FragmentLoopCount(L.getKey(), L.getValue());
fc_count += f.FragmentFunctionCallsCount(L.getKey(), L.getValue());
fd_count += f.FragmentFunctionDeclsCount(L.getKey(), L.getValue());
}
}
//--------------------------------------------------
}
public boolean ArrayBelongsToRegion(long id) {
2025-05-10 17:15:45 +03:00
return arraysMap.values().stream().anyMatch(array -> array.id == id);
2023-09-17 22:13:42 +03:00
}
public ProjectArray getArrayById(long id) {
2025-05-10 17:15:45 +03:00
for (ProjectArray array : arraysMap.values()) {
2023-09-17 22:13:42 +03:00
if (array.id == id) return array;
}
return null;
}
@Override
public String toString() {
return "Область распараллеливания: " + originalName;
}
@Override
public Object getPK() {
return regionId;
}
public void UpdateLoopsCount() {
loops_count = 0;
for (String FKey : lines.keySet()) {
2025-05-10 17:15:45 +03:00
for (IntegerPairJson L : lines.get(FKey)) {
DBProjectFile f = Global.mainModule.getProject().db.files.Data.get(FKey);
2023-09-17 22:13:42 +03:00
loops_count += f.FragmentLoopCount(L.getKey(), L.getValue());
}
}
}
public void UpdateFunctionsCount() {
fd_count = 0;
fc_count = 0;
for (String FKey : lines.keySet()) {
2025-05-10 17:15:45 +03:00
for (IntegerPairJson L : lines.get(FKey)) {
DBProjectFile f = Global.mainModule.getProject().db.files.Data.get(FKey);
2023-09-17 22:13:42 +03:00
fc_count += f.FragmentFunctionCallsCount(L.getKey(), L.getValue());
fd_count += f.FragmentFunctionDeclsCount(L.getKey(), L.getValue());
}
}
}
public void UpdateArraysCount() {
2024-10-14 15:19:13 +03:00
arrays_count = 0;
2023-09-17 22:13:42 +03:00
for (String FKey : lines.keySet()) {
2025-05-10 17:15:45 +03:00
for (IntegerPairJson L : lines.get(FKey)) {
DBProjectFile f = Global.mainModule.getProject().db.files.Data.get(FKey);
2023-09-17 22:13:42 +03:00
arrays_count += f.FragmentArraysCount(L.getKey(), L.getValue());
}
}
}
}