Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libraries
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
libraries
Commits
de7902f7
Commit
de7902f7
authored
2 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
multithread C++ solver
parent
643d8743
No related branches found
No related tags found
No related merge requests found
Pipeline
#22974
passed
2 years ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/frep-C.py
+41
-23
41 additions, 23 deletions
python/frep-C.py
with
41 additions
and
23 deletions
python/frep-C.py
+
41
−
23
View file @
de7902f7
#!/usr/bin/env python3
#
# frep-C.py
# functional representation to C++ solver
# functional representation to C++
multi-threaded
solver
#
# usage:
# pcb.py | frep-C.py [dpi [filename]]
#
# Neil Gershenfeld 8/23/21
# (c) Massachusetts Institute of Technology 2021
# Neil Gershenfeld 11/26/22
#
# This work may be reproduced, modified, distributed,
# performed, and displayed for any purpose, but must
...
...
@@ -71,12 +70,11 @@ file.write(
f
"""
#include <iostream>
#include <cmath>
#include <thread>
#include <png.h>
//
using namespace std;
int fn(float X,float Y,float Z) {{
return (
{
fn
}
);
}}
int main(int argc, char** argv) {{
//
float xmin =
{
xmin
}
;
float xmax =
{
xmax
}
;
float ymin =
{
ymin
}
;
...
...
@@ -90,15 +88,25 @@ int main(int argc, char** argv) {{
int ny = (ymax-ymin)/delta;
int *m = (int*) calloc(nx*ny,sizeof(int));
float layers[] = {{
{
layers
}
}};
int nthreads = std::thread::hardware_concurrency();
//
int fn(float X,float Y,float Z) {{
return (
{
fn
}
);
}}
//
void calc(int nx,int ny,int nthreads,int thread) {{
int intensity;
for (int layer = 0; layer <
{
nlayers
}
; ++layer) {{
for (int layer = 0; layer <
2
; ++layer) {{
float z = layers[layer];
if (thread == 0)
cout <<
"
z =
"
<< z << endl;
if (zmin == zmax)
intensity = 0x
FFFFFF
;
intensity = 0x
ffffff
;
else
intensity = ((int) (255*(z-zmin)/(zmax-zmin))) | (255 << 8) | (255 << 16);
for (int iy = 0; iy < ny; ++iy) {{
int iystart = thread*ny/nthreads;
int iyend = (thread+1)*ny/nthreads;
for (int iy = iystart; iy < iyend; ++iy) {{
float y = ymin+iy*delta;
for (int ix = 0; ix < nx; ++ix) {{
float x = xmin+ix*delta;
...
...
@@ -106,6 +114,16 @@ int main(int argc, char** argv) {{
}}
}}
}}
}}
//
int main(int argc, char** argv) {{
cout <<
"
calculate
"
<< nx <<
"
x
"
<< ny <<
"
with
"
<< nthreads <<
"
threads
"
<< endl;
std::thread threads[nthreads];
for (int i = 0; i < nthreads; ++i)
threads[i] = std::thread(calc,nx,ny,nthreads,i);
for (int i = 0; i < nthreads; ++i)
threads[i].join();
//
FILE *file;
file = fopen(
"
{
filename
}
"
,
"
wb
"
);
png_structp pngfile;
...
...
@@ -138,7 +156,7 @@ file.close()
# compile
#
print
(
"
compile ...
"
)
os
.
system
(
"
time g++ frep-C.cpp -o frep-C -lm -lpng -O -ffast-math
"
)
os
.
system
(
"
time g++ frep-C.cpp -o frep-C -lm -lpng -O -ffast-math
-pthread
"
)
#
# execute
#
...
...
@@ -147,4 +165,4 @@ os.system("time ./frep-C")
#
# clean up
#
os
.
system
(
"
rm -f frep-C.cpp frep-C
"
)
#
os.system("rm -f frep-C.cpp frep-C")
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment