首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
program程序代做、代写C++程序语言
项目预算:
开发周期:
发布时间:
要求地区:
Assignment 1
Introduction
In Assignment 1, students will learn to use system calls.
System Calls
Manage Files
int open(const char *pathname, int flags, ...
/* mode_t mode */ );
ssize_t read(int fd, void buf[.count], size_t count);
ssize_t write(int fd, const void buf[.count], size_t count);
open()
The open() system call opens the file specified by pathname. If the specified file does not exist,
it may optionally (if O_CREAT is specified in flags) be created by open().
The return value of open() is a file descriptor, a small, nonnegative integer that is an index to an
entry in the process's table of open file descriptors. The file descriptor is used in subsequent
system calls (read(2), write(2), lseek(2), fcntl(2), etc.) to refer to the open file. The file descriptor
returned by a successful call will be the lowest-numbered file descriptor not currently open for
the process.
read()
read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.
On files that support seeking, the read operation commences at the file offset, and the file offset
is incremented by the number of bytes read. If the file offset is at or past the end of file, no bytes
are read, and read() returns zero.
If count is zero, read() may detect the errors described below. In the absence of any errors, or if
read() does not check for errors, a read() with a count of 0 returns zero and has no other effects.
write()
write() writes up to count bytes from the buffer starting at buf to the file referred to by the file
descriptor fd.
The number of bytes written may be less than count if, for example, there is insufficient space on
the underlying physical medium, or the RLIMIT_FSIZE resource limit is encountered
(seesetrlimit(2)), or the call was interrupted by a signal handler after having written less than
count bytes. (See also pipe(7).)
For a seekable file (i.e., one to which lseek(2) may be applied, for example, a regular file) writing
takes place at the file offset, and the file offset is incremented by the number of bytes actually
written. If the file was open(2)ed with O_APPEND, the file offset is first set to the end of the file
before writing.
The adjustment of the file offset and the write operation are performed as an atomic step.
Map files
mmap() creates a new mapping in the virtual address space of the calling process. The starting
address for the new mapping is specified in addr. The length argument specifies the length of
the mapping (which must be greater than 0).
For more details, see mmap(2) - Linux manual page
void *mmap(void addr[.length], size_t length, int prot, int flags,int fd, off_t
offset);
int munmap(void addr[.length], size_t length);
Process
pid_t fork(void);
pid_t wait(int *_Nullable wstatus);
pid_t waitpid(pid_t pid, int *_Nullable wstatus, int options);
int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
fork()
fork() creates a new process by duplicating the calling process.
The new process is referred to as the child process. The calling process is referred to as the
parent process.
The child process and the parent process run in separate memory spaces. At the time of fork()
both memory spaces have the same content.
Memory writes, file mappings (mmap(2)), and unmappings
(munmap(2)) performed by one of the processes do not affect the other.
The child process is an exact duplicate of the parent process except for the following points:
• The child has its own unique process ID, and this PID does not match the ID of any existing
process group (setpgid(2)) or session.
• The child's parent process ID is the same as the parent's process ID.
• The child does not inherit its parent's memory locks (mlock(2), mlockall(2)).
For more details, see fork(2) - Linux manual page
wait()
All of these system calls are used to wait for state changes in a child of the calling process, and
obtain information about the child whose state has changed. A state change is considered to be:
the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In
the case of a terminated child, performing a wait allows the system to release the resources
associated with the child; if a wait is not performed, then the terminated child remains in a
"zombie" state (see NOTES below).
If a child has already changed state, then these calls return immediately. Otherwise, they block
until either a child changes state or a signal handler interrupts the call (assuming that system
calls are not automatically restarted using the SA_RESTART flag of sigaction(2)). In the
remainder of this page, a child whose state has changed and which has not yet been waited
upon by one of these system calls is termed waitable.
Graph Preleminary
Graph Layout
OA : Offset Array.
NA : Neighbor Array.
In our implementation, the graph is in CSR format. Which means that, if you want to know the
neighbor of node i , get OA[i] and OA[i+1] , the index range of NA that stores
neighbors.
In the graph.size file, it has 8 bytes, which are the number of nodes and number of edges.
( |nodes| , |edges| )
In the graph file, the first |nodes|+1 *4 Bytes are values of OA . The following |edges| *4
Bytes are values of NA . The last |edges| *4 Bytes are values of edge weight for
corresponding edge.
Dataset Download
You can get dataset, and sample output of Assignment 1 from the following link:
CSC3150_23-24Term2_A1_data - OneDrive
Your dataset should be placed at the same directory of code
main@ubuntu:~/Desktop$ ls
a.out grader g1 g1.size g2 g2.size graph.cpp graph.h sample_output
Important
In this assignment, all datasets to read and output files you need to write are in binary format.
Please take a look at std::ios::binary .
sample_output is used for self-checking if the answers to task1 are correct.
Task1
In task1, you are provided with data sets graph1 , graph2 correspondings to Task1_1
and Task1_2 . In such graphs, the nodes can be represented as cities, edges between cities
can be represented as roads. We provide a program traversing nodes through BFS algorithm.
Figure: Transportation Graph
• Your first task is to complete the remaining part of program so that it can correctly load data
into memory and do BFS traverse execution.
• After BFS traversal is done, the program needs to store the sequence of visits to the result file.
• In the following progress charts, blocks in yellow means it's a file, in red means it's a TODO
part for you.
• In this task, you need to complete Task1_1(), Task1_2() . In Task1_2() we only
have 2GB memory but g2 has 1.8GB data. Traditional read from disk to memory does not
work.
Hint
• When loading the graph, please note that OA has length |nodes|+1 instead of
|nodes| . This is because we miantain one more integer for some boundary problems.
What you read from the .size file is |nodes| and |edges| .
Task2
In task 2, the program goes into a simple simulation. In the daytime, a node gains weights from
its edges with corresponding edge weights, implemented by produce() . In the night, a
node's weight will self-increased by 1, implemented by consume() .
The global view of process is shown in the figure below. We highlight the components you needs
to do in green and yellow blocks:
You are required to use fork() to handle two processes. For the parent process, we will do
calculation of produce() . For the child process, we will do consume() . Both of these
functions are provided, you do not need to do any modification to it.
// Executed in parent process
void produce(int *weights, int len, Graph &g) {
for (int i=0; i
int l,r;
g.get_edge_index(i,l,r);
for (int j=l;j
weights[i+1]+=g.edge_weights[j];
}
}
}
// Executed in child process
void consume(int *weights, int len, Graph &g) {
for (int i=0; i
weights[i+1] += 1;
}
}
TODO
• Your task is to complete the following functions with correct system call and control logic so
that program runs correctly as shown in the above figrue.
• In implementation of communication, it actually shares the data stored in weights
◦ Format of array weights : the first integer should be the value of current iteration (start
from 0). The following |V| integers are corresponding weights of vertex
• For each iteration generated by child process, child process should write result to file
e.g. For 4th and 5th iterations, write sequence of nodes weight to
/home/csc3150/A1/Task2_parent.output_2 and
/home/csc3150/A1/Task2_child.output_2 .
• Program terminates at 10th iteration
// Task2: Process Inter-Communicationvoid Task2() {
Graph g;
int fd;
fd = g.map_global_graph("g2");
std::string ipc_path("ipc_file");
// Creating inter process communication file if there is not.
int ipc_fd = open(ipc_path.c_str(),O_RDWR| O_CREAT,0777);
lseek (ipc_fd, (g.v_cnt+1)*sizeof(int)-1, SEEK_SET);
write (ipc_fd, "", 1);
close(ipc_fd);
std::string output_parent_path("Task2_parent.output");
std::string output_child_path("Task2_child.output");
// process control
}
// Task2: Process Inter-Communication with control
void parent_process(const std::string &path) {
int pid = getpid();
printf("parent proc %d is producing\n",pid);
// produce()
return;
}
// Task2: Process Inter-Communication with control
void child_process(const std::string &path) {
int pid = getpid();
printf("child proc %d is consuming\n",pid);
// consume()
return;
}
Hint
• The status of vertices need to be communicated inter-process at each iteration because both
processes need to process/ fetch data.
• You might need to define index 0 of mapped file in mmap() as control int
◦ Because of Data Dependency, execution order matters
◦ By reading control byte, each process will know whether they should wait, process, or
terminate.
• You can use mmap() to share reading the data graph if both processes need information of
graph.
◦ Try to figure out how memory is consumed when multi-process using mmap map to one
file.
Output files
You are expected to generate the following files when you complete all the tasks
All these files are in the same directory as graph.h, graph.c
(wrong file name will not be correctly graded):
Report 10'
You shall strictly follow the provided latex template for the report, where we have emphasized
important parts and respective grading details. Reports based on other templates will not be
graded.
Report Template
• You can find latex template in the following link
◦ https://www.overleaf.com/read/ybgnjwnyvjpx#dd17ed
• We also provide template at BB.
LaTex Editor
For your convenience, you might use Overleaf, an online LaTex Editor.
1. Create a new blank project.
2. Click the following highlight bottom and upload the template we provide.
3. Click Recompile and you will see your report in PDF format.
Extra Credit
Instead of using shared memory space for inter-process communication, you are required to
implement Task2 with using message passing.
Using any profiling tools to compare performance of communication via shared memory
(mmap) and message passing.
Report your result and your discovery.
Hint
• You can use pipe() to pass updated messages from parent process to child process/ or from
child process to parent process.
• You can learn to use dtrace for profiling in this task.
Execution
main@ubuntu:~/Desktop$ g++ graph.cpp
main@ubuntu:~/Desktop$ ./a.out
Submission
• Due on: 23:59, 28 Feb 2023
• Plagiarism is strictly forbidden. Please note that TAs may ask you to explain the meaning of
your program to ensure that the codes are indeed written by yourself. Please also note that
we would check whether your program is too similar to your fellow students' code and
solutions available on the internet using plagiarism detectors.
• Late submission: A late submission within 15 minutes will not induce any penalty on your
grades. But 00:16 am-1:00 am: Reduced by 10%; 1:01 am-2:00 am: Reduced by 20%; 2:01
am-3:00 am: Reduced by 30% and so on. (e.g., Li Hua submitted a perfect attempt at 2:10
a.m. He will get (100+10 (bonus))*0.7=77p
• Any incorrect execution results by the following reasons are not arguable (Please double
check before submit)
◦ Compile error (Ensure no modification on header file)
◦ Incorrect file name/ path (Please strictly follow naming and path provided in instruction
and template)
◦ Successfully running program with incorrect result
Format guide
The project structure is illustrated below. You can also use ls command to check if your
structure is fine. Structure mismatch would cause grade deduction.
For this assignment, you don't need a specific folder for the bonus part. The source folder
should contain four files: graph.c, report.pdf . Please note that graph.h is not need to submit.
We limit your implementation within graph.c file, starting with "Task:" comments.
main@ubuntu:~/Desktop/Assignment_3_120010001$ ls
report.pdf graph.c
(One directory and one pdf.)
Please compress all files in the file structure root folder into a single zip file and name it using
your student ID as the code shown below and above, for example,
Assignment_3_120010001.zip. The report should be submitted in the format of pdf, together
with your source code. Format mismatch would cause grade deduction. Here is the sample step
for compressing your code.
main@ubuntu:~/Desktop$
zip -q -r Assignment_1_120010001.zip Assignment_3_120010001
main@ubuntu:~/Desktop$ ls
Assignment_1_120010001 Assignment_1_120010001.zip
Grading Rules
Program part 90'
You can test the correctness of your output using the following commands under directory.
• Execution with argument 0 will simply return grade
• Execution with argument 1 will return the test result of each case (1 for correct, 0 for wrong).
main@ubuntu:~/Desktop$ ./grader 1
Test result 1 0 0
main@ubuntu:~/Desktop$ ./grader 0
20
Task1_1 20p
Task1_2 30p
Task2 40p
Report 10p
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!