Java Python Due Sep 23 by 11:59pm Points 70 Submitting a file upload
Available Sep 13 at 10am - Dec 24 at 11:59pm
Start Assignment
Assignment 2 (70 Points)
Due Monday Sep 23 at 11:59 PM
In this assignment, you need to parallelize simple programs using C++11 threads. There are two
problems in this assignment, and for each problem you are provided the serial C++ implementation, the
expected parallelization strategy, and the expected output to be generated by your parallel solution.
Before starting this assignment, you should have completed the Slurm Tutorial
(https://canvas.sfu.ca/courses/84236/pages/slurm-tutorial) which walks you through how to use our
private cluster for your code development. [NOTE: The cluster is not set up to run Slurm yet, so
please start the assignment on CSIL machines. We will send an announcement when the cluster
is ready.]
General Instructions
1. You are provided with the serial version of all the programs at assignment2.tar.gz
(https://canvas.sfu.ca/courses/84236/files/24448336?wrap=1)
(https://canvas.sfu.ca/courses/84236/files/24448336/download?download_frd=1) . To run a program
(e.g., curve_area.cpp ), follow the steps below:
Run make curve_area . This creates a binary file called curve_area .
Create a slurm job to run the binary file using the following command: ./curve_area --nPoints
10000000 --coeffA 2.0 --coeffB 4.0? --rSeed 15
Use the command-line argument --nPoints to specify the number of points to be generated
(detailed description about curve_area mentioned below).
2. All parallel programs should have the command-line argument --nThreads to specify the number of
threads for the program. Example: --nThreads 4 .
3. While testing your solutions, make sure that cpus-per-task is correctly specified in your slurm
config file based on your requirement.
4. You will be asked to print the time spent by different threads on specific code regions. The time spent
by any code region can be computed as follows:
timer t1;
t1.start();
Assignment 2
1/6
/* ---- Code region whose time is to be measured --- */
double time_taken = t1.stop();
5. Sample outputs for all the programs can be found in sample_outputs directory. Programs will be
evaluated and graded automatically. Please make sure that your program output strictly
follows the sample output format.
6. We have provided test scripts for you to quickly test your solutions during your development process.
You can test your code using the test script available at test_scripts/ . Note that these test scripts
only validate the output formats, and a different evaluation script will be used for grading the
assignments. Important: You should use slurm when performing these and other tests. The test
scripts under test_scripts/ folder test for up to 8 threads; make sure --cpus-per-task=8 is set in
your slurm job.
$ ls test_scripts/*tester.pyc
curve_area_tester.pyc heat_transfer_tester.pyc
1. Monte Carlo Estimation of Area Inside a Curve [25 Points]
The area inside an arbitrary curve can be computed using the mechanism explained in class, similar to
the Monte Carlo Pi Estimation and Monte Carlo Ellipse Area Estimation. In this problem, you will
compute the area inside a curve with the following equation:
Where a and b are positive numbers. For example, the curve represented by is shown
here:
Another example: The curve represented by is shown here:
The method can be summarized in the following steps:
Assignment 2
2/6
1. Consider a curve that follows the above equation with coefficients a and b. For the purposes of this
problem, both coefficients are >= 1. With these coefficient values, the curve will be completely
enclosed inside a square with corner coordinates (-1,-1), (-1,1), (1,1), (1,-1).
2. The ratio of the curve area to the square area is determined by the relative count of points inside the
curve to total points inside the square.
3. We randomly generate n points inside the square, where both the x-coordinate and y-coordinate are
between -1 and 1. Let cpoints out of the n points fall inside the curve. A point is determined to be
inside the curve if
4. The area inside the curve is then approximated as: Area / 4 = cpoints / n ==> Area = 4 *
cpoints / n .
The program below implements the above algorithm.
uint curve_count = 0;
double x_coord, y_coord;
for (uint i = 0; i < n; i++) {
x_coord = (2.0 * get_random_coordinate(&random_seed)) - 1.0);
y_coord = (2.0 * get_random_coordinate(&random_seed)) - 1.0);
if ( (a * (x^2)) + (b * (y^4)) ) <= 1.0)
curve_count++;
}
double area = 4.0 * (double)curve_points / (double)n;
Your goal is to parallelize the above algorithm. Specifically, we are interested in parallelizing the for loop
such that each thread generates (approximately) n/T points, where T is the number of threads. Below
is the pseudo-code showing the logic of our parallel solution:
Create T threads
for each thread in parallel {
Get the local_curve_count for (approximately) n/T points
}
total_curve_points = Accumulate the local_curve_counts from all threads ? ?
area = 4.0 *(double)total_curve_points / (double)n;
The serial implementation is available in curve_area.cpp . You have to parallelize the given serial
implementation using C++11 threads.
Your parallel solution must satisfy the following:
1. The file should be named curve_area_parallel.cpp .
2. Your program should accept the following parameters:
nThreads: Number of threads.
nPoints: Total number of points used for estimating the area. This number should be divided
equ threads Assignment 2 ally among threads (with the remainder r=nPoints % nThreads going to threads 0,...,r-1 )
coeffA: Value of coefficient a.
coeffB: Value of coefficient b.
rSeed: Seed of the random number generator that you use in the program.
3. Your parallel solution must output the following information:
Assignment 2
3/6
Total number of threads used.
For each thread: the number of random points generated, the number of points within the curve,
and the time taken to generate and process these points (your threads should be numbered
between [0, T) ).
The total number of points generated.
The total number of points within the curve.
The total time taken for the entire execution (the code region to be timed is highlighted using
comments in the serial code).
4. The sample output can be found in sample_outputs/curve_area.output .
Please note that the output format should strictly match the expected format (including "spaces" and
"commas"). You can test your code using the test script as follows:
$ python /curve_area_tester.pyc --execPath=
--scriptPath=/curve_area_evaluator.pyc
2. Heat Transfer [45 Points]
A description of the heat transfer problem was discussed in class, and is also available from the LLNL
Parallel Computing Tutorial here (https://hpc.llnl.gov/training/tutorials/introduction-parallel-computing?tutorial#ExamplesHeat) . The following code shows the basic serial implementation for this problem:
// Initialize Temperature Array Prev[][]. Points in the middle are set to mTemp while rest is se
t to 0
for (uint stepcount=1; stepcount <= tSteps; stepcount ++) {
for (uint x = 0; x < gSize; x++) {
for (uint (y = 0; y < gSize; y++) {
// Compute new Temperature Array Curr[x][y] from Prev[][] values
} // for y
} // for x
// swap Prev[][], Curr[][]
} // for stepcount
// Print temperature of certain points in Temperature Array
Your goal is to parallelize the above algorithm such that each thread works on a vertical slice of the
array. Below is the pseudo-code showing the logic of the parallel solution:
Create T threads
for each thread in parallel {
for (uint local_stepcount=1; local_stepcount <= tSteps; local_stepcount ++) {
Compute the Temperature Array values Curr[][] in the slice allocated to this thread from Pre
v[][]
Barrier(); // all threads need to finish current time step
if (this is thread 0) { swap Curr[][], Prev[][]; Barrier(); }
else Barrier(); // wait till thread 0 is done with the swap before moving to next time step
} // for local_stepcount
} // for each thread
// Print temperatures of points of interest
The serial implementation is available in heat_transfer.cpp . You have to parallelize the given serial
implementation using C++11 threads. For your parallel code, you can use the custom barrier
Assignment 2
4/6
implementation available in core/utils.h or you can implement your own
1. The file should be named heat_transfer_parallel.cpp . Your program should accept the following
parameters:
nThreads: Total number of threads used.
gSize: Grid size. The size of the temperature array is gSize x gSize.
mTemp: Temperature values in the middle of the array, from [gSize/3 , gSize/3] to [2*gSize/3 ,
2*gSize/3].
iCX: Coefficient of horizontal heat transfer.
iCY: Coefficient of vertical heat transfer.
tSteps: Time steps of the simulation
2. Your parallel solution must output the following information:
Grid Size.
Total number of threads used.
Values of iCX, iCY, mTemp and tSteps
For each thread: thread id, start column, end column, time taken.
Temperatures at end of simulation for points at [0,0], [gSize/6, gSize/6], [gSize/3, gSize/3],
[gSize/2, gSize/2], [2*gSize/3, 2*gSize/3], [5*gSize/6, 5*gSize/6].
Temperatures at the right boundary of all threads: [endx[0], endx[0]], [endx[1], endx[1]], ...,
[[endx[nThreads-1],endx[nThreads-1]].
The total time taken for the entire execution (the code region to be timed is highlighted using
comments in the serial code).
3. The sample console output can be found in sample_outputs/heat_transfer.output .
Please note that the output format should strictly match the expected format (including "spaces" and
"commas"). You can test your code using the test script as follows:
$ python /test_scripts/heat_transfer_tester.pyc --execPath=h of heat_tranfer_parallel> --scriptPath=
Submission Guidelines
Make sure that your solutions folder has the following files and sub-folders. Let's say your solutions
folder is called my_assignment2_solutions . It should contain:
core/ -- The folder containing all core files. It is already available in the assignment package. Do
not modify it or remove any files.
Makefile -- Makefile for the assignment. This file should not be changed.
curve_area_parallel.cpp
heat_transfer_parallel.cpp
To create the submission file, follow the steps below:
1. Enter in your solutions folder, and remove all the object/temporary files.
Assignment 2
5/6
$ cd my_assignment2_solutions/
$ make clean
2. Create the tar.gz file.
$ tar cvzf assignment2.tar.gz *
which creates a compressed tar ball that contains the contents of the folder.
3. Validate the tar ball using the submission_validator.pyc script.
$ python /test_scripts/submission_validator.pyc --tarPath=ath>/assignment2.tar.gz
Submit via canvas by the deadline
相关推荐
物联网技术(AIR780E cat1-4G模块+小程序+腾讯云MQTT)驱动的智能井盖系统设计(连载01)
终端设备采用AIR780E模块作为主控器,电子模块有三轴加速度传感器、可燃气体传感器,AIR780E模块(4G模块)通过MQTT通信协议进行数据打包上传至EMQX服务器,在EMQX服务器中,用户可以自行订阅主题和发布主题,小程序通过MQTT通信协议订阅EMQX服务器的主题,服务器通过接收到硬件发布的数据,转发到微信小程序。
FFmpeg限制CPU的使用率,使用“-threads 2”
–threads 2 参数 使用–threads 2 可以将CPU的使用率控制在50%左右。 FFmpeg -i IN –threads 2 OUT 源文链接:https://stackoverflow.com/questions/11357713/how-to-limit-ffmpeg-cpu-usage The solution as outlined here How...
保姆级教程:用YOLOv8n模型在RKNN和Horizon平台完成目标检测(附C++部署代码与性能实测)
本文提供了一份详尽的YOLOv8n模型在RKNN和Horizon平台上的部署指南,涵盖环境配置、模型优化、跨平台适配及性能调优。通过实战案例和C++部署代码,帮助开发者在嵌入式设备上高效实现目标检测,显著提升推理性能。
ffmpeg threads_FFmpeg限制CPU的使用率,使用“-threads 2”
–threads 2 参数使用–threads 2 可以将CPU的使用率控制在50%左右。FFmpeg -i IN –threads 2 OUT源文链接:https://stackoverflow.com/questions/11357713/how-to-limit-ffmpeg-cpu-usageThe solution as outlined hereis to limit the n...
手把手教你用UM982搭建厘米级RTK定位系统(附避坑指南)
本文详细介绍了如何使用UM982模组搭建厘米级RTK定位系统,涵盖硬件连接、软件配置和深度优化技巧。UM982支持BDS、GPS、GLONASS和Galileo等多系统全频点信号,特别适合精准农业、无人机导航等高精度应用场景。通过实战案例和避坑指南,帮助开发者快速实现厘米级定位精度。
YOLOV8多模态(可见光+红外光目标检测任务,基于Ultralytics官方代码实现)
torch 2.3.1 torchvision 0.18.1 Python 3.8.19 tensorrt 8.5.3.1DroneVehicle数据集下载地址DroneVehicle 数据集由无人机采集的 56,878 张图像组成,其中一半是 RGB 图像,其余是红外图像。我们为这 5 个类别制作了丰富的注释,其中包含定向边界框。其中,汽车在 RGB 图像中有 389,779 个注释,在
llama2.c多线程优化:如何合理设置OMP_NUM_THREADS参数
在大语言模型推理过程中,矩阵乘法(matmul)操作占据了绝大部分计算时间。llama2.c项目通过OpenMP实现了多线程并行计算,能够显著提升推理速度。但盲目设置线程数不仅无法获得最佳性能,甚至可能导致性能下降。本文将深入探讨如何科学合理地设置`OMP_NUM_THREADS`参数,实现最佳性能优化。 ## OpenMP在llama2.c中的实现原理 ### 核心并行化区域 llama2...
探索niri:让你的Linux桌面布局无拘无束
niri是一款基于Wayland的滚动平铺合成器,采用创新的窗口管理方式。它将窗口排列为向右无限延伸的条目,支持独立显示器布局和动态垂直工作区,确保多任务操作流畅性。核心功能包括概要视图、截图界面、屏幕投射、手势操作、窗口分组等,并支持自定义布局和动画效果。niri具备良好的稳定性,兼容xwayland-satellite工具,灵感来自PaperWM但突破了GNOME限制。该项目为追求高效桌面管理的用户提供了全新解决方案,欢迎加入社区交流体验。
突破Llama2推理速度瓶颈:OMP_NUM_THREADS参数调优实战指南
你是否还在忍受Llama2模型推理时的漫长等待?当输入提示后,终端光标闪烁却迟迟没有响应——这很可能是CPU线程配置不合理导致的资源浪费。本文将通过实战案例告诉你:如何通过优化OMP_NUM_THREADS环境变量,让llama2.c在普通PC上实现2-5倍的速度提升。读完本文你将掌握:线程数与模型层数的匹配公式、不同硬件配置的参数组合、以及通过性能监控工具找到最优配置的方法。 ## 为什么线程...
Hermes 教程 05:多 Agent 编排
本文介绍了Hermes v0.13.0中的四种多Agent协作模式:1)delegate_task快速子任务模式,适合2-3个独立并行任务;2)spawn子Agent模式,实现零成本并行多步流水线;3)tmux交互子Agent模式,支持长期自主任务;4)全新Kanban看板系统,提供持久化AI团队协作框架。各模式在隔离级别、时长、工具访问和适用场景上存在差异,其中spawn模式通过独立上下文窗口实现零上下文成本。文章详细说明了每种模式的使用方法、限制条件和典型应用场景,并提供了具体代码示例和可视化流程图。K
RK3588,V4l2 读取Gmsl相机, Rga yuv422转换rgb (dma), 实现零拷贝
RK3588, 使用V4l2 读取 gmsl 相机,获得yuv422格式图像, 使用 rga 转换 rgb 图像。减少cpu占用率. 内存管理方式采用 dma,实现零拷贝.
week 2 - Threads
• 允许用户自定义处理逻辑,例如日志记录、清理资源等。5. 线程取消(Thread Cancellation)
《干货满满!AI 应用架构师打造 AI 驱动生产计划的实战技巧》
生产计划是制造企业的“大脑”——它决定了买什么物料、产多少产品、用什么设备、什么时候交货,直接影响企业的成本、效率和客户满意度。需求预测靠经验,误差常超20%;排产依赖Excel,调整一次要3天;供应链协同靠邮件,物料延迟导致停产屡见不鲜。作为AI应用架构师,我们的任务是用AI重新“激活”这个“大脑”——用数据驱动的预测替代经验判断,用智能优化替代人工排产,用实时协同替代被动响应。本文结合3个制造业实战案例5段可运行代码2个数字孪生模型,从架构设计→核心模块实现→落地踩坑。
SpringBoot max-threads设置方式(2.3 版本以后)
目前网上文章写设置SpringBoot tomcat 的max_threads 的方法为:server.tomcat.max-threads=250 但是在springboot 2.3 以后已经修改为 server.tomcat.threads.max=400 老的设置会不生效 验证方法 @Configuration public class EmbedTomcatConfig { @Bean WebServerFactoryCustomizer<ConfigurableServle
廖雪峰Python教程[完整版]
廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白
VC中sqlite的使用
在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示
start 2 threads
package HeadFirstJava; public class RunThreads implements Runnable { public static void main(String[] args) { RunThreads runner = new RunThreads(); // make a Runnable object Thre
霍尼韦尔SoftMaster使用说明
霍尼韦尔SoftMaster使用说明
Chandra参数详解:Ollama中gemma:2b的batch_size、num_threads对CPU/GPU利用率影响
本文介绍了如何在星图GPU平台上自动化部署Chandra - AI 聊天助手镜像,实现本地私有化AI对话功能。通过优化Ollama框架中的batch_size和num_threads参数,可显著提升CPU/GPU利用率,为个人和企业提供安全、高效的本地AI聊天解决方案。
精雕软件(JDpaint) 5.5 绿色版
精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版
Chapter2 Managing threads
In this chapter I covered the basics of thread management with the C++ Standard Library: starting threads, waiting for them to finish, and not waiting for them to finish because you want them to run in the background. You also saw how to pass
2-PROCESSES AND THREADS
Please indicate the source: http://blog.youkuaiyun.com/gaoxiangnumber1 Welcome to my github: https://github.com/gaoxiangnumber12.1 PROCESSES In any multiprogramming system, the CPU switches from process to
Ollama部署all-MiniLM-L6-v2性能调优:batch_size、num_ctx、threads参数详解
本文介绍了如何在星图GPU平台自动化部署all-MiniLM-L6-v2镜像,实现高效的句子嵌入和语义理解任务。该轻量级模型适用于文档相似度计算、智能问答等场景,通过调整batch_size、num_ctx等参数可显著提升推理性能和资源利用率。
srs源码分析2-浅析state_threads
srs是基于协程开发的,底层使用了state_threads协程库。为了更好的理解srs,所以需要先熟悉state_threads。这里并不会介绍协程的相关概念,只是简单的介绍一下state_threads的核心逻辑。 以下state_thread会被简称为st。 使用示例-echo server 使用st实现了一个简单的echo服务器,以下代码写的很简单,重点是理解st的使用。 #include <arpa/inet.h> #include <errno.h> #include &
2.7线程Threads
线程是进程中的一个实体,是被系统独立调度和分派的基本单位。在多线程OS中,通常是在一个进程中包括多个线程。 1.线程的引入: 引入线程的目的:减少程序在并发执行时所付出的时空开销,在追求效率的前提下实现并发。 注: 利用进程实现的多道程序系统中,频繁的进程切换会浪费大量时空开销。限制并发程度问题所在:进程实体信息量大,对进程的管理操作越多,与运行时间的比值就越大,运行效率就低。 当A进程内的a1...
【2】Android Processes And Threads
Android 中的进程和线程基本知识点: 什么是进程?什么是线程?二者的关系 四大组件的 android:process 属性 进程的五级重要层次结构 进程的分类:前台进程、可见进程、服务进程、后台进程、空进程 Android 单线程模式的两条基本规则 在工作线程访问UI的几种办法: 使用 AsyncTask 线程安全方法 参考文档: (1)、官方GUIDE
all-MiniLM-L6-v2生产环境调优:batch_size/num_threads/num_ctx参数详解
本文介绍了如何在星图GPU平台上自动化部署all-MiniLM-L6-v2镜像,实现高效语义搜索与向量检索。通过平台一键部署该轻量级嵌入模型,可快速构建RAG系统或知识库问答服务,广泛应用于电商商品检索、客服语义匹配等典型场景。
[OS] 再探Kernel Threads -2
用于创建一个新的内核线程,但不会立即启动,必须使用来唤醒线程。返回值:成功时返回,失败时返回ERR_PTR。:用于启动由创建的线程,将其加入调度队列。1表示成功唤醒线程,0表示线程已经在运行。:这是一个便捷函数,结合了和的功能,创建并启动线程。返回值:成功时返回,失败时返回ERR_PTR。通过使用,可以简化内核线程的创建和启动过程,避免显式调用。if (!return 0;\n");模块和内核线程的初始化包含了必要的内核头文件,如。
Ollama部署internlm2-chat-1.8b参数详解:num_ctx、num_threads、temperature设置
本文介绍了如何在星图GPU平台上自动化部署【书生·浦语】internlm2-chat-1.8b镜像,并详细解析了num_ctx、num_threads和temperature等核心参数的设置方法。该模型适用于多种场景,如智能客服对话,通过调整参数可优化生成文本的连贯性和创意性,提升交互体验。
1.2.2合并线程(Joining Threads)
一个线程(像主线程)有时候需要开始一个其它线程去执行大量数据的计算、下载文件或执行耗时的活动。在完成其它任务之后,这个线程就会开始工作线程,而这个工作线程已经准备好了去执行工作线程的结果返回和等待工作线程完成和死亡。 Thread提供三个join()方法,这个方法允许线程去等待其它线程,谁调用了object join()方法谁就会死亡。 void join():无限期等
2219



被折叠的 条评论
为什么被折叠?



