CS代写|计算机项目代写:Project 2 – Concurrency Using Threads

Keywords: CS 360 Project 2, Concurrency Using Threads, WordCount assignment, multithreading file search project

Project 2 – Concurrency Using Threads

CS 360 – Winter 2026

Due Date: March 18, 2026

Objective

This project focuses on understanding how multithreading improves performance by increasing parallelism within a process. Threads allow multiple tasks to execute simultaneously, especially on multi-core systems. The goal is to compare the performance of a single-threaded program with a multi-threaded program when searching files.

Project Description

You will develop a program that searches thousands of files for a specific word. The program should output the total number of occurrences of the word and the time required to complete the search.

The program must support both single-threaded and multi-threaded execution, depending on user input. You will conduct experiments to compare performance based on execution time.

You may use any programming language that supports multithreading (such as C#, Java, etc.).

Task Requirements

1. Develop an application named “WordCount” using a programming language that supports multithreading.

2. The program should prompt the user to input the following information:

  • The full path of the folder containing files
  • The number of files to search
  • The word to search for
  • The number of threads to use

Input validation must include:

  • The folder must exist
  • The number of files must be an integer ≥ 0
  • The search word cannot be empty
  • The number of threads must be 0 (single-threaded) or a positive integer

3. Program Output

  • Total number of occurrences of the search word
  • Total execution time

The results should be consistent between single-threaded and multi-threaded runs (same word count).

Experiment 1: Single-threaded Performance

Run the program with 0 threads. Choose any word and perform the following tests:

  • 125 files → run 5 times, calculate average
  • 250 files → run 5 times, calculate average
  • 500 files → run 5 times, calculate average
  • 1000 files → run 5 times, calculate average

Create a scatter plot:

  • X-axis: Number of files
  • Y-axis: Average time (seconds)
  • Title: “Single-threaded Performance”

Experiment 2: Multi-threaded Performance

Run the program using multiple threads.

Test with:

  • Files: 125, 250, 500, 1000
  • Threads: 2, 5, 10, 15, 20

For each combination:

  • Run 3 times
  • Calculate average

Create a scatter plot:

  • X-axis: Number of threads
  • Y-axis: Average time
  • Include 4 lines (one per file size)
  • Title: “Thread Count Performance”

Experiment 3: Comparison

Use existing data (no new runs required).

  • Select the thread count with best performance
  • Compare it with single-threaded results

Create a scatter plot:

  • X-axis: Number of files
  • Y-axis: Average time
  • Two lines:
    • Single-threaded
    • Multi-threaded
  • Title: “Single-threaded vs. Multi-threaded Search Performance”

Implementation Notes

  • Use time as the performance metric
  • Record execution time using appropriate tools (e.g., Stopwatch in C#)
  • Avoid race conditions when updating shared variables
  • Ensure thread-safe operations (e.g., atomic updates)

Submission Requirements

Create a folder: firstName_lastName_proj2

Include:

  • Raw experimental data (Excel or images)
  • Source code
  • A PDF containing 3 graphs and answers to the following:
  1. Does search time increase with number of files?
  2. Does increasing threads always improve performance? Why or why not?
  3. Why is multithreading faster than single-threading?

Zip the folder and submit it before the deadline.

Grading Criteria

  • Source Code: 60%
  • Experimental Data: 15%
  • PDF (graphs + answers): 20%
  • Graph Quality: 5%

项目2 – 基于线程的并发编程

CS 360 – 2026年冬季学期

截止日期:2026年3月18日

项目目标

本项目旨在帮助理解多线程如何通过在一个进程内增加并行性来提升性能。线程允许多个任务同时执行,尤其是在多核系统中。本项目的目标是比较单线程程序与多线程程序在文件搜索任务中的性能表现。

项目说明

你需要开发一个程序,用于在大量文件中搜索指定的单词。程序需要输出该单词出现的总次数以及完成搜索所需的时间。

该程序必须支持单线程和多线程两种执行方式,并根据用户输入进行切换。你需要通过实验比较不同执行方式下的性能差异。

你可以使用任何支持多线程的编程语言(例如 C#、Java 等)。

任务要求

1. 使用支持多线程的编程语言开发一个名为“WordCount”的应用程序。

2. 程序应提示用户输入以下信息:

  • 包含文件的文件夹完整路径
  • 需要搜索的文件数量
  • 要搜索的单词
  • 使用的线程数量

输入验证要求包括:

  • 文件夹路径必须存在
  • 文件数量必须为大于等于0的整数
  • 搜索词不能为空
  • 线程数量必须为0(表示单线程)或正整数

3. 程序输出

  • 搜索词出现的总次数
  • 程序执行的总时间

注意:单线程和多线程运行结果应保持一致(即单词出现次数相同)。

实验一:单线程性能

在线程数为0的情况下运行程序。选择任意一个单词,并执行以下测试:

  • 125个文件 → 运行5次,计算平均值
  • 250个文件 → 运行5次,计算平均值
  • 500个文件 → 运行5次,计算平均值
  • 1000个文件 → 运行5次,计算平均值

绘制散点图:

  • X轴:文件数量
  • Y轴:平均时间(秒)
  • 标题:“单线程性能”

实验二:多线程性能

使用多个线程运行程序。

测试条件如下:

  • 文件数量:125、250、500、1000
  • 线程数量:2、5、10、15、20

对于每种组合:

  • 运行3次
  • 计算平均值

绘制散点图:

  • X轴:线程数量
  • Y轴:平均时间
  • 包含4条曲线(每种文件数量一条)
  • 标题:“线程数量性能”

实验三:对比分析

使用已有实验数据(无需重新运行)。

  • 选择性能最佳的线程数量
  • 与单线程结果进行对比

绘制散点图:

  • X轴:文件数量
  • Y轴:平均时间
  • 两条曲线:
    • 单线程
    • 多线程
  • 标题:“单线程与多线程性能对比”

实现说明

  • 使用时间作为性能衡量指标
  • 使用合适的工具记录执行时间(例如 C# 中的 Stopwatch)
  • 避免在更新共享变量时出现竞态条件
  • 确保线程安全操作(例如原子更新)

提交要求

创建一个文件夹:firstName_lastName_proj2

包含以下内容:

  • 实验原始数据(Excel或图片)
  • 源代码
  • 一个PDF文件,其中包含3个图表以及以下问题的答案:
  1. 随着文件数量增加,搜索时间是否会增加?
  2. 增加线程数量是否一定会提升性能?为什么或为什么不?
  3. 为什么多线程比单线程更快?

请将文件夹压缩为zip文件,并在截止日期前提交。

评分标准

  • 源代码:60%
  • 实验数据:15%
  • PDF报告(图表 + 问题回答):20%
  • 图表质量:5%