Actual source code: aoserialize.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: aoserialize.c,v 1.3 2000/01/10 03:15:40 knepley Exp $";
3: #endif
5: #include src/dm/ao/aoimpl.h
7: /*@
8: AOSerialize - This function stores or recreates an application ordering using a viewer for a binary file.
10: Collective on comm
12: Input Parameters:
13: + comm - The communicator for the ordering object
14: . viewer - The viewer context
15: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
17: Output Parameter:
18: . ao - The ordering
20: Level: beginner
22: .keywords: serialize, ordering
23: .seealso: VecSerialize()
24: @*/
25: int AOSerialize(MPI_Comm comm, AO *ao, PetscViewer viewer, PetscTruth store)
26: {
27: int (*serialize)(MPI_Comm, AO *, PetscViewer, PetscTruth);
28: int fd, len;
29: char *name;
30: PetscTruth match;
31: int ierr;
37: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
38: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
39: PetscViewerBinaryGetDescriptor(viewer, &fd);
41: if (store) {
43: PetscStrlen((*ao)->class_name, &len);
44: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
45: PetscBinaryWrite(fd, (*ao)->class_name, len, PETSC_CHAR, 0);
46: PetscStrlen((*ao)->serialize_name, &len);
47: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
48: PetscBinaryWrite(fd, (*ao)->serialize_name, len, PETSC_CHAR, 0);
49: PetscFListFind(comm, AOSerializeList, (*ao)->serialize_name, (void (**)(void)) &serialize);
50: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
51: (*serialize)(comm, ao, viewer, store);
52: } else {
53: PetscBinaryRead(fd, &len, 1, PETSC_INT);
54: PetscMalloc((len+1) * sizeof(char), &name);
55: name[len] = 0;
56: PetscBinaryRead(fd, name, len, PETSC_CHAR);
57: PetscStrcmp(name, "AO", &match);
58: PetscFree(name);
59: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-ordering object");
60: /* Dispatch to the correct routine */
61: if (!AOSerializeRegisterAllCalled) {
62: AOSerializeRegisterAll(PETSC_NULL);
63: }
64: if (!AOSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
65: PetscBinaryRead(fd, &len, 1, PETSC_INT);
66: PetscMalloc((len+1) * sizeof(char), &name);
67: name[len] = 0;
68: PetscBinaryRead(fd, name, len, PETSC_CHAR);
69: PetscFListFind(comm, AOSerializeList, name, (void (**)(void)) &serialize);
70: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
71: (*serialize)(comm, ao, viewer, store);
72: PetscStrfree((*ao)->serialize_name);
73: (*ao)->serialize_name = name;
74: }
76: return(0);
77: }