d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Make Me A Better Programmer - From Step 1
Prev1313233343556Next
Add Reply New Topic New Poll
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Feb 28 2014 01:43pm
Quote (m0hawk @ Feb 28 2014 10:43am)
its actually farily easy once you've understood it properly  :P


Well, I don't know if I understand it fully properly.

I know there is a count variable, I know there are methods to 'wait' and 'signal another semaphore' (using the sembuf struct iirc).

I just gotta figure out how to implement it for my current project.

We have to simulate heat transfer across a rod.

I know I will need an array of n semaphores, each corresponding to a column in the 2d array I use to solve the problem.

Each 'worker' process corresponds to a column. The workers are assigned to solve ui,j+1, but need to know ui-1,j && ui,j && ui+1,j in order to solve it (that is, their neighbors values).

(where i is process ID, j is a 'unit of time' (your choice of unit) and ui,j being the temperature at position i at time j of the rod

There is a lot more to it, but I need to become really familiar with the C semaphore stuff.

This post was edited by Eep on Feb 28 2014 01:45pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 28 2014 02:51pm
Quote (0n35 @ Feb 28 2014 11:07am)
Claim ruby is a god send

Still uses php

http://i.imgur.com/MTrxNlI.png


Ruby is god sent, Rails isn't. If you knew anything outside of php you would know this. Try again?

Php is the nickleback of programming languages...

This post was edited by AbDuCt on Feb 28 2014 02:54pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Feb 28 2014 03:27pm
Quote (AbDuCt @ Feb 28 2014 03:51pm)
Ruby is god sent, Rails isn't. If you knew anything outside of php you would know this. Try again?

Php is the nickleback of programming languages...


twenty-something women love php?

This post was edited by Eep on Feb 28 2014 03:27pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 28 2014 05:02pm
Quote (Eep @ Feb 28 2014 05:27pm)
twenty-something women love php?


I guess lol.

It's tough having access to the best of all languages in one organized place: string processing from perl, list processing from lisp, OO from smalltalk, iterators from CLU, ect.
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Feb 28 2014 09:14pm
Quote (AbDuCt @ Feb 28 2014 06:02pm)
I guess lol.

It's tough having access to the best of all languages in one organized place: string processing from perl, list processing from lisp, OO from smalltalk, iterators from CLU, ect.


But look at what you lose from PHP:

api calls that are thin, poorly error-checked wrappers around C libraries, object equality that doesn't work quite right and a slew of really awesome properties that can break an entire environment accidentally and silently. How could you not like PHP?
Member
Posts: 24,488
Joined: Jul 11 2011
Gold: 1,272.50
Feb 28 2014 09:50pm
Quote (Eep @ 13 Feb 2014 00:44)
This weekend is gonna be fun

Code
Concurrent UNIX Processes and shared memory
The goal of this homework is to become familiar with concurrent processing in the Unix operating system. You
will write a program that uses multiple processes to compute the product of two matrices Anm and Bmk. Each
element of the resultant matrix C is given by

There are two types of processes for this homework:

 A \coordinator" process: It is responsible for creating the \worker" processes, and coordinating the computa-
tion. Note that all the computation is done by the \worker" processes. All the information is provided in the
command line (argv).

 A set of \worker" processes: Each worker process reads two integer indices i and j from its argv, computes
the result using expression 1 and returns the result into shared memory before exiting. So, a worker process
is created for every element of the resultant matrix C.

The coordinator process also set a timer at the start of computation. If computation has not  nished by this time,
the coordinator process kills all the workers and then exits. Make sure that you print appropriate message(s).

The code for worker process should be compiled separately and its executable be called worker. The executable for
the coordinator process should be called coord. The two matrices to be multiplied should be kept in separate  les
whose names are to be provided as command line arguments. Thus the program should be executed by

coord -t time A.mat B.mat C.mat

where time is the duration after which the program will be killed (default value: 100).
The format of each matrix  le with n rows and m columns is as follows:
n m
a11 a12 a13    a1m
a21 a22 a23    a2m
a31 a32 a33    a3m
...
...
...
...
...
an1 an2 an3    anm

Each worker process prints its process id, its operands and their sum. Each time coord gets a message back from a
worker, it prints the pid of the worker and the result received into the log  le.

Implementation

The coordinator will create the matrices in the shared memory after reading them from the files, and write the result
into a third file after all the children have  finished.

The code for coordinator and worker processes should be compiled separately and the executables be called coord
and worker.

coord will just spawn the worker processes and wait for them to  nish. Make sure that you never have more than
twenty processes at any time in the system, no matter how big the matrix. coord also sets a timer at the start of
computation to a speci ed number of seconds (default 100). If computation has not  nished by this time, coord kills
all the worker processes and then exits. Make sure that you print appropriate message(s).

In addition, coord should print a message when an interrupt signal (^C) is received. Other signals are ignored. The
child processes will be killed when the interrupt is received by coord. Then, coord should be killed as well. You can
kill the children explicitly from coord, or by sending a signal to self. Make sure that the processes handle multiple
interrupts correctly. As a precaution, add this feature only after your program is well debugged.

coord will also allocate shared memory for synchronization purposes (flag and turn). Each child will write into a
log  le created by coord. The information to go in the log  le will be the point when the worker attempts to enter
the critical section, and when it exits the critical section. You should keep track of the number of times worker
attempted to enter critical section before it succeeded and write that information in the log le. Writing into the
log le will be performed from inside the critical section. Also add a sleep function in the critical section to sleep for
a random amount of time between 0 and 3 seconds.

The code for main and child processes should be compiled separately and the executables be called coord and worker.
Hints
You will need to set up shared memory in this project to allow the processes to communicate with each other. Please
check the man pages for shmget, shmctl, shmat, and shmdt to work with shared memory.

You will also need to set up signal processing and to do that, you will check on the functions for signal and abort.
If you abort a process, make sure that the parent cleans up any allocated shared memory before dying.
In case you face problems, please use the shell commands ipcs to  nd out any shared memory allocated to you and
free it by using ipcrm.


not allowed to use bakery algorithm :[


Looks like your professor is trying to re-invent the wheel.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 28 2014 09:56pm
Quote (HighschoolTurd @ Feb 28 2014 10:50pm)
Looks like your professor is trying to re-invent the wheel.


That's kind of the point of the class though. You don't teach a data structures course by saying "someone already did all this and made it available in a library." No, you teach them the concepts behind it, and have them implement their own version.
Member
Posts: 24,488
Joined: Jul 11 2011
Gold: 1,272.50
Mar 1 2014 01:32am
Quote (Minkomonster @ 28 Feb 2014 20:56)
That's kind of the point of the class though. You don't teach a data structures course by saying "someone already did all this and made it available in a library." No, you teach them the concepts behind it, and have them implement their own version.


True to an extent, but depends on that program and how it's used in the real world. And also if it's actually intuitive. I do get your point and I do agree.

This post was edited by HighschoolTurd on Mar 1 2014 01:32am
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 1 2014 01:48am
Quote (HighschoolTurd @ Mar 1 2014 02:32am)
True to an extent, but depends on that program and how it's used in the real world. And also if it's actually intuitive. I do get your point and I do agree.


Most programming assignments given to CS majors are geared towards teaching a concept and not necessarily aimed towards real world application. I have yet to come across a situation where knowing how to implement self balancing data structures has proved beneficial in the work place. It doesn't even cross my mind. I just import whatever Dictionary implementation I need and go about my business.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 1 2014 02:00pm
Quote (rockonkenshin @ Feb 28 2014 11:14pm)
But look at what you lose from PHP:

api calls that are thin, poorly error-checked wrappers around C libraries, object equality that doesn't work quite right and a slew of really awesome properties that can break an entire environment accidentally and silently. How could you not like PHP?


I just recently updated to ruby 2.0 after they finally hit the p4xx release and announced that 1.9.3 is no longer industry standard and will lose support in except for security fixes later in 2014, and will be discontinued all together in 2015. Mean while I finally decided to install Rails. It's pretty sexy, but Rails is pretty confusing up front. You have so many views and controllers and database shit you have to create. Just to create a simple page to output "hello world" it requires you to create a welcome controller with a #index action, a welcome index.html.erb view to display your hello world, and then change the routes to redirect / "root" to /welcome/index.

I can see how it makes creating large database sites easy though, must be why so many high profile websites ditched php and went to rails, such as twitter, hulu, justin.tv, urban dictonary, github, ect.

This post was edited by AbDuCt on Mar 1 2014 02:01pm
Go Back To Programming & Development Topic List
Prev1313233343556Next
Add Reply New Topic New Poll